From 4ee0b253e6b5ccba730def74e3864f528678a663 Mon Sep 17 00:00:00 2001 From: Federico Simoncelli Date: May 24 2012 15:19:26 +0000 Subject: log: add the thread id in the log messages Signed-off-by: Federico Simoncelli --- diff --git a/src/log.c b/src/log.c index 614a855..fc516bc 100644 --- a/src/log.c +++ b/src/log.c @@ -21,6 +21,8 @@ #include #include #include +#include +#include #include #include "sanlock_internal.h" @@ -120,6 +122,7 @@ void log_level(uint32_t space_id, uint32_t token_id, char *name_in, int level, c int len = LOG_STR_LEN - 2; /* leave room for \n\0 */ struct timeval cur_time; struct tm time_info; + pid_t tid; memset(name, 0, sizeof(name)); @@ -137,11 +140,13 @@ void log_level(uint32_t space_id, uint32_t token_id, char *name_in, int level, c 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); + "%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); + tid = syscall(SYS_gettid); + + ret = snprintf(log_str + pos, len - pos, "%llu [%u]: %s", + (unsigned long long) monotime(), tid, name); pos += ret; va_start(ap, fmt);