From: Ben Pfaff Date: Wed, 16 Jul 2008 21:38:20 +0000 (-0700) Subject: Include date and time in vlog messages. X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=21bcd54543d9a676e3c81c5a156ec2fa0fc0f677;p=openvswitch Include date and time in vlog messages. --- diff --git a/lib/vlog.c b/lib/vlog.c index 17f20a2c..8cd0c271 100644 --- a/lib/vlog.c +++ b/lib/vlog.c @@ -40,6 +40,7 @@ #include #include #include +#include #include "dynamic-string.h" #include "util.h" @@ -305,11 +306,18 @@ vlog(enum vlog_module module, enum vlog_level level, const char *message, ...) static int msg_num; const char *module_name = vlog_get_module_name(module); const char *level_name = vlog_get_level_name(level); + time_t now; + struct tm tm; va_list args; char s[1024]; - size_t len; + size_t len, time_len; - len = sprintf(s, "%05d|%s|%s:", ++msg_num, module_name, level_name); + now = time(0); + localtime_r(&now, &tm); + + len = time_len = strftime(s, sizeof s, "%b %d %H:%M:%S|", &tm); + len += sprintf(s + len, "%05d|%s|%s:", + ++msg_num, module_name, level_name); va_start(args, message); len += vsnprintf(s + len, sizeof s - len, message, args); va_end(args); @@ -332,7 +340,7 @@ vlog(enum vlog_module module, enum vlog_level level, const char *message, ...) [VLL_DBG] = LOG_DEBUG, }; - syslog(syslog_levels[level], "%s", s); + syslog(syslog_levels[level], "%s", s + time_len); } errno = save_errno; }