From 37e63909c09359ddd5baf7a237387ee5f7219c2d Mon Sep 17 00:00:00 2001 From: Steven Young Date: Wed, 16 Feb 2000 17:32:49 +0000 Subject: This commit was generated by cvs2svn to compensate for changes in r2, which included commits to RCS files with non-trunk default branches. --- src/log.c | 90 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 src/log.c (limited to 'src/log.c') diff --git a/src/log.c b/src/log.c new file mode 100644 index 0000000..ca64f8e --- /dev/null +++ b/src/log.c @@ -0,0 +1,90 @@ +/* $Id: log.c,v 1.1.1.1 2000-02-16 17:32:22 sdyoung Exp $ + * + * Logs the various messages which tinyproxy produces to either a log file or + * the syslog daemon. Not much to it... + * + * Copyright (C) 1998 Steven Young + * Copyright (C) 1999 Robert James Kaes (rjkaes@flarenet.com) + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2, or (at your option) any + * later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * log.c - For the manipulation of log files. + */ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include +#include +#include +#include +#include +#include +#include + +#include "tinyproxy.h" +#include "log.h" + +#define LENGTH 16 + +/* + * This routine logs messages to either the log file or the syslog function. + */ +void log(char *fmt, ...) +{ + va_list args; + time_t nowtime; + FILE *cf; + +#if defined(HAVE_SYSLOG_H) && !defined(HAVE_VSYSLOG_H) + static char str[800]; +#endif + static char time_string[LENGTH]; + + assert(fmt); + + va_start(args, fmt); + +#ifdef HAVE_SYSLOG_H + if (config.syslog == FALSE) { +#endif + nowtime = time(NULL); + /* Format is month day hour:minute:second (24 time) */ + strftime(time_string, LENGTH, "%b %d %H:%M:%S", + localtime(&nowtime)); + + if (!(cf = config.logf)) + cf = stderr; + + fprintf(cf, "%s [%d]: ", time_string, getpid()); + vfprintf(cf, fmt, args); + fprintf(cf, "\n"); + fflush(cf); +#ifdef HAVE_SYSLOG_H + } else { +# ifdef HAVE_VSYSLOG_H + vsyslog(LOG_INFO, fmt, args); +# else +# ifdef HAVE_VSNPRINTF + vsnprintf(str, 800, fmt, args); +# else +# ifdef HAVE_VPRINTF + vsprintf(str, fmt, args); +# endif +# endif + syslog(LOG_INFO, str); +# endif + } +#endif + + va_end(args); +} -- cgit v1.2.3