diff options
author | Nick Mathewson <nickm@torproject.org> | 2003-06-17 21:36:44 +0000 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2003-06-17 21:36:44 +0000 |
commit | 5fd033a8e8d98161888964e53b58e31d226df3f3 (patch) | |
tree | 3e7cda29906bcaf5c02ac8db08e873a25c4f22b1 /src/common | |
parent | b9480620c61e1eb5115353e1ff79c2d676d70964 (diff) | |
download | tor-5fd033a8e8d98161888964e53b58e31d226df3f3.tar tor-5fd033a8e8d98161888964e53b58e31d226df3f3.tar.gz |
Come up with a less macro-happy, even more portable log_fn implementation
svn:r331
Diffstat (limited to 'src/common')
-rw-r--r-- | src/common/log.c | 56 | ||||
-rw-r--r-- | src/common/log.h | 9 |
2 files changed, 37 insertions, 28 deletions
diff --git a/src/common/log.c b/src/common/log.c index 303995120..92c0b3781 100644 --- a/src/common/log.c +++ b/src/common/log.c @@ -42,36 +42,50 @@ size_t sev_to_string(char *buf, int max, int severity) { return strlen(buf)+1; } -/* Outputs a message to stdout */ -void log(int severity, const char *format, ...) +static void +logv(int severity, const char *funcname, const char *format, va_list ap) { static int loglevel = LOG_DEBUG; char buf[201]; time_t t; - va_list ap; struct timeval now; - + if (format) { - if(gettimeofday(&now,NULL) < 0) + if (severity > loglevel) + return; + if (gettimeofday(&now,NULL) < 0) return; - va_start(ap,format); - - if (severity <= loglevel) - { - t = time(NULL); - strftime(buf, 200, "%b %d %H:%M:%S", localtime(&t)); - printf("%s.%.3ld ", buf, (long)now.tv_usec / 1000); - sev_to_string(buf, 200, severity); - printf("[%s] ", buf); - vprintf(format,ap); - printf("\n"); - } - - va_end(ap); - } - else + t = time(NULL); + strftime(buf, 200, "%b %d %H:%M:%S", localtime(&t)); + printf("%s.%.3ld ", buf, (long)now.tv_usec / 1000); + sev_to_string(buf, 200, severity); + printf("[%s] ", buf); + if (funcname) + printf("%s(): ", funcname); + vprintf(format,ap); + printf("\n"); + } else loglevel = severity; + +} + +/* Outputs a message to stdout */ +void log(int severity, const char *format, ...) +{ + va_list ap; + va_start(ap,format); + logv(severity, NULL, format, ap); + va_end(ap); } +void _log_fn(int severity, const char *fn, const char *format, ...) +{ + va_list ap; + va_start(ap,format); + logv(severity, fn, format, ap); + va_end(ap); +} + + diff --git a/src/common/log.h b/src/common/log.h index 5669a511a..635b15dbd 100644 --- a/src/common/log.h +++ b/src/common/log.h @@ -13,16 +13,11 @@ void log(int severity, const char *format, ...); #ifdef __GNUC__ -#ifdef __APPLE_CPP__ +void _log_fn(int severity, const char *funcname, const char *format, ...); #define log_fn(severity, args...) \ - log((severity), __PRETTY_FUNCTION__ "(): " args) -#else -#define log_fn(severity, format, args...) \ - log((severity), "%s(): " format, __PRETTY_FUNCTION__ , ##args) -#endif + _log_fn(severity, __PRETTY_FUNCTION__, args) #else #define log_fn log -#define log_fnf log #endif # define __LOG_H |