summaryrefslogtreecommitdiff
path: root/src/log.c
diff options
context:
space:
mode:
authorRobert James Kaes <rjkaes@users.sourceforge.net>2000-09-11 23:47:52 +0000
committerRobert James Kaes <rjkaes@users.sourceforge.net>2000-09-11 23:47:52 +0000
commit4f4f91f76ff33c65f2f0da2ce17bf8f52907dcf9 (patch)
tree59fe49b704666dafa6b2e9f18b353330cd8b69d1 /src/log.c
parent5d7063a79e79bf3ae3723e4fd751205cbd740c23 (diff)
downloadtinyproxy-4f4f91f76ff33c65f2f0da2ce17bf8f52907dcf9.tar.gz
tinyproxy-4f4f91f76ff33c65f2f0da2ce17bf8f52907dcf9.zip
Cleaned up the logging format, and also included logging levels (which are
similar to the syslogd format.)
Diffstat (limited to '')
-rw-r--r--src/log.c64
1 files changed, 29 insertions, 35 deletions
diff --git a/src/log.c b/src/log.c
index ca64f8e..407ff80 100644
--- a/src/log.c
+++ b/src/log.c
@@ -1,4 +1,4 @@
-/* $Id: log.c,v 1.1.1.1 2000-02-16 17:32:22 sdyoung Exp $
+/* $Id: log.c,v 1.2 2000-09-11 23:47:52 rjkaes Exp $
*
* Logs the various messages which tinyproxy produces to either a log file or
* the syslog daemon. Not much to it...
@@ -15,74 +15,68 @@
* 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 <defines.h>
-#endif
+#include "tinyproxy.h"
-#include <stdio.h>
#include <stdarg.h>
-#include <time.h>
-#include <syslog.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <assert.h>
-#include "tinyproxy.h"
#include "log.h"
-#define LENGTH 16
+static char *syslog_level[] = {
+ NULL,
+ NULL,
+ "CRITICAL",
+ "ERROR",
+ "WARNING",
+ NULL,
+ "INFO",
+ "DEBUG"
+};
+
+#define TIME_LENGTH 16
+#define STRING_LENGTH 800
/*
* This routine logs messages to either the log file or the syslog function.
*/
-void log(char *fmt, ...)
+void log(short int level, char *fmt, ...)
{
va_list args;
time_t nowtime;
FILE *cf;
+ char time_string[TIME_LENGTH];
#if defined(HAVE_SYSLOG_H) && !defined(HAVE_VSYSLOG_H)
- static char str[800];
+ char str[STRING_LENGTH];
#endif
- static char time_string[LENGTH];
-
- assert(fmt);
va_start(args, fmt);
#ifdef HAVE_SYSLOG_H
- if (config.syslog == FALSE) {
+ if (config.syslog) {
+# ifdef HAVE_VSYSLOG_H
+ vsyslog(level, fmt, args);
+# else
+ vsnprintf(str, STRING_LENGTH, fmt, args);
+ syslog(level, str);
+# endif
+ } else {
#endif
nowtime = time(NULL);
/* Format is month day hour:minute:second (24 time) */
- strftime(time_string, LENGTH, "%b %d %H:%M:%S",
+ strftime(time_string, TIME_LENGTH, "%b %d %H:%M:%S",
localtime(&nowtime));
if (!(cf = config.logf))
cf = stderr;
- fprintf(cf, "%s [%d]: ", time_string, getpid());
+ fprintf(cf, "%-9s %s [%d]: ", syslog_level[level],
+ 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