diff options
Diffstat (limited to 'src/common')
-rw-r--r-- | src/common/log.c | 39 | ||||
-rw-r--r-- | src/common/log.h | 2 |
2 files changed, 23 insertions, 18 deletions
diff --git a/src/common/log.c b/src/common/log.c index 92c0b3781e..12785d8704 100644 --- a/src/common/log.c +++ b/src/common/log.c @@ -42,33 +42,36 @@ size_t sev_to_string(char *buf, int max, int severity) { return strlen(buf)+1; } +static int loglevel = LOG_DEBUG; + 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; struct timeval now; - if (format) { - - if (severity > loglevel) - return; - if (gettimeofday(&now,NULL) < 0) - return; + assert(format); + if (severity > loglevel) + return; + if (gettimeofday(&now,NULL) < 0) + return; - 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; + 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"); +} +void +log_set_severity(int severity) +{ + loglevel = severity; } /* Outputs a message to stdout */ diff --git a/src/common/log.h b/src/common/log.h index 0cf7c0dd6d..2d77009ad1 100644 --- a/src/common/log.h +++ b/src/common/log.h @@ -17,6 +17,8 @@ #define CHECK_PRINTF(formatIdx, firstArg) #endif +void log_set_severity(int severity); + /* Outputs a message to stdout and also logs the same message using syslog. */ void log(int severity, const char *format, ...) CHECK_PRINTF(2,3); |