src/log.c | 9 +++++++++ 1 file changed, 9 insertions(+)
New commits: commit 97d4c881e6ed4e035cf1511801f4fa593f9e67c6 Author: Federico Simoncelli fsimonce@redhat.com Date: Tue May 22 13:33:12 2012 +0000
log: add full time and date to the log messages
In order to correlate sanlock logs with other logs (eg: libvirt, VDSM) it is useful to log the full time and date of the messages.
Signed-off-by: Federico Simoncelli fsimonce@redhat.com
diff --git a/src/log.c b/src/log.c index 73595fc..614a855 100644 --- a/src/log.c +++ b/src/log.c @@ -20,6 +20,7 @@ #include <syslog.h> #include <pthread.h> #include <sys/socket.h> +#include <sys/time.h> #include <stdarg.h>
#include "sanlock_internal.h" @@ -117,6 +118,8 @@ void log_level(uint32_t space_id, uint32_t token_id, char *name_in, int level, c char name[NAME_ID_SIZE + 1]; int ret, pos = 0; int len = LOG_STR_LEN - 2; /* leave room for \n\0 */ + struct timeval cur_time; + struct tm time_info;
memset(name, 0, sizeof(name));
@@ -131,6 +134,12 @@ void log_level(uint32_t space_id, uint32_t token_id, char *name_in, int level, c
pthread_mutex_lock(&log_mutex);
+ gettimeofday(&cur_time, NULL); + localtime_r(&cur_time.tv_sec, &time_info); + ret = strftime(log_str + pos, len - pos, + "%Y-%m-%d %H:%M:%S%z: ", &time_info); + pos += ret; + ret = snprintf(log_str + pos, len - pos, "%llu %s", (unsigned long long)monotime(), name); pos += ret;
sanlock-devel@lists.fedorahosted.org