diff options
author | Roger Dingledine <arma@torproject.org> | 2002-09-04 00:39:33 +0000 |
---|---|---|
committer | Roger Dingledine <arma@torproject.org> | 2002-09-04 00:39:33 +0000 |
commit | 4eb0158f4225460b2e714e73475c9e5bc7ccefd7 (patch) | |
tree | a11f212b9fb6dda495327273c51820c1d9f5a072 | |
parent | adfd11b9acf55fc874750dad539bfa6dd0cbf11b (diff) | |
download | tor-4eb0158f4225460b2e714e73475c9e5bc7ccefd7.tar tor-4eb0158f4225460b2e714e73475c9e5bc7ccefd7.tar.gz |
the logs now include a timestamp and severity
the implementation is sort of a kludge..you're welcome to fix it up
svn:r94
-rw-r--r-- | src/common/log.c | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/src/common/log.c b/src/common/log.c index 27212aeab..8c0a06252 100644 --- a/src/common/log.c +++ b/src/common/log.c @@ -8,6 +8,11 @@ /* * Changes : * $Log$ + * Revision 1.3 2002/09/04 00:39:33 arma + * the logs now include a timestamp and severity + * + * the implementation is sort of a kludge..you're welcome to fix it up + * * Revision 1.2 2002/07/12 18:14:16 montrose * removed loglevel from global namespace. severity level is set using log() with a NULL format argument now. example: log(LOG_ERR,NULL); * @@ -55,12 +60,53 @@ #include <syslog.h> #include <string.h> #include <errno.h> +#include <assert.h> +#include <time.h> #include "log.h" +/* FIXME this whole thing is hacked together. feel free to make it clean. */ +size_t sev_to_string(char *buf, int max, int severity) { + assert(max > 20); + + switch(severity) { + case LOG_DEBUG: + strcpy(buf,"debug"); + break; + case LOG_INFO: + strcpy(buf,"info"); + break; + case LOG_NOTICE: + strcpy(buf,"notice"); + break; + case LOG_WARNING: + strcpy(buf,"warn"); + break; + case LOG_ERR: + strcpy(buf,"err"); + break; + case LOG_CRIT: + strcpy(buf,"crit"); + break; + case LOG_ALERT: + strcpy(buf,"alert"); + break; + case LOG_EMERG: + strcpy(buf,"emerg"); + break; + default: + strcpy(buf,"UNKNOWN"); + break; + } + + return strlen(buf)+1; +} + /* Outputs a message to stdout */ void log(int severity, const char *format, ...) { static int loglevel = LOG_DEBUG; + char buf[201]; + time_t t; va_list ap; if ( format ) @@ -70,6 +116,11 @@ void log(int severity, const char *format, ...) if (severity <= loglevel) { + t = time(NULL); + strftime(buf, 200, "%b %d %H:%M:%S", localtime(&t)); + printf("%s ", buf); + sev_to_string(buf, 200, severity); + printf("[%s] ", buf); vprintf(format,ap); printf("\n"); } @@ -79,3 +130,4 @@ void log(int severity, const char *format, ...) else loglevel = severity; } + |