From 3047188b314b3d2a4788451d2b7ab633b8d127ff Mon Sep 17 00:00:00 2001 From: Vijay Bellur Date: Thu, 20 May 2010 07:24:28 +0000 Subject: libglusterfs: Use usecond resolution for logging Signed-off-by: Vijay Bellur Signed-off-by: Anand V. Avati BUG: 936 (Provide microsecond timestamp in logfile) URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=936 --- libglusterfs/src/logging.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'libglusterfs/src') diff --git a/libglusterfs/src/logging.c b/libglusterfs/src/logging.c index 7fbcacb4e44..e298b327e51 100644 --- a/libglusterfs/src/logging.c +++ b/libglusterfs/src/logging.c @@ -153,9 +153,9 @@ _gf_log (const char *domain, const char *file, const char *function, int line, const char *basename = NULL; FILE *new_logfile = NULL; va_list ap; - time_t utime = 0; struct tm *tm = NULL; char timestr[256]; + struct timeval tv = {0,}; char *str1 = NULL; char *str2 = NULL; @@ -200,8 +200,11 @@ _gf_log (const char *domain, const char *file, const char *function, int line, } log: - utime = time (NULL); - tm = localtime (&utime); + ret = gettimeofday (&tv, NULL); + if (-1 == ret) + goto out; + + tm = localtime (&tv.tv_sec); if (level > loglevel) { goto out; @@ -212,6 +215,8 @@ log: va_start (ap, fmt); strftime (timestr, 256, "%Y-%m-%d %H:%M:%S", tm); + snprintf (timestr + strlen (timestr), 256 - strlen (timestr), + ".%ld", tv.tv_usec); basename = strrchr (file, '/'); if (basename) -- cgit