From fa70eff67e327b181e3d006a3381ae8e32822084 Mon Sep 17 00:00:00 2001 From: Nir Soffer Date: Nov 07 2016 17:32:13 +0000 Subject: Add option to log UTC timestamps To make it easier to debug cluster issues, management system may like to use UTC timestamps on all machines in the cluster. This patch adds a logfile_use_utc option to allow a management system to configure sanlock for its needs. The default is 0, keeping old behaviour expected by existing users. Signed-off-by: Nir Soffer --- diff --git a/src/log.c b/src/log.c index fc516bc..df9d87a 100644 --- a/src/log.c +++ b/src/log.c @@ -58,6 +58,7 @@ static char logfile_path[PATH_MAX]; static FILE *logfile_fp; extern int log_logfile_priority; +extern int log_logfile_use_utc; extern int log_syslog_priority; extern int log_stderr_priority; @@ -138,9 +139,14 @@ 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); + + if (log_logfile_use_utc) + gmtime_r(&cur_time.tv_sec, &time_info); + else + localtime_r(&cur_time.tv_sec, &time_info); + ret = strftime(log_str + pos, len - pos, - "%Y-%m-%d %H:%M:%S%z ", &time_info); + "%Y-%m-%d %H:%M:%S ", &time_info); pos += ret; tid = syscall(SYS_gettid); diff --git a/src/main.c b/src/main.c index 83db458..b68720f 100644 --- a/src/main.c +++ b/src/main.c @@ -73,6 +73,7 @@ struct thread_pool { /* priorities are LOG_* from syslog.h */ int log_logfile_priority = LOG_WARNING; +int log_logfile_use_utc = 0; int log_syslog_priority = LOG_ERR; int log_stderr_priority = -1; /* -D sets this to LOG_DEBUG */ @@ -2297,6 +2298,10 @@ static void read_config_file(void) get_val_int(line, &val); log_logfile_priority = val; + } else if (!strcmp(str, "logfile_use_utc")) { + get_val_int(line, &val); + log_logfile_use_utc = val; + } else if (!strcmp(str, "syslog_priority")) { get_val_int(line, &val); log_syslog_priority = val; diff --git a/src/sanlock.conf b/src/sanlock.conf index 062692f..af753d1 100644 --- a/src/sanlock.conf +++ b/src/sanlock.conf @@ -14,6 +14,9 @@ # logfile_priority = 3 # command line: -L 3 # +# logfile_use_utc = 0 +# command line: n/a +# # syslog_priority = 3 # command line: -S 3 #