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(a)redhat.com>
---
src/log.c | 9 +++++++++
1 files changed, 9 insertions(+), 0 deletions(-)
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;
--
1.7.1