zookeeper-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From maha...@apache.org
Subject svn commit: r726862 - in /hadoop/zookeeper/trunk: CHANGES.txt src/c/src/zk_log.c
Date Mon, 15 Dec 2008 22:36:25 GMT
Author: mahadev
Date: Mon Dec 15 14:36:25 2008
New Revision: 726862

URL: http://svn.apache.org/viewvc?rev=726862&view=rev
Log:
ZOOKEEPER-222.  print C client log message timestamp in human readable form. (pat via mahadev)

Modified:
    hadoop/zookeeper/trunk/CHANGES.txt
    hadoop/zookeeper/trunk/src/c/src/zk_log.c

Modified: hadoop/zookeeper/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/CHANGES.txt?rev=726862&r1=726861&r2=726862&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/CHANGES.txt (original)
+++ hadoop/zookeeper/trunk/CHANGES.txt Mon Dec 15 14:36:25 2008
@@ -78,6 +78,9 @@
    ZOOKEEPER-225. c client should log an info message in zookeeper_init
 detailing connection parameters. (pat via mahadev)
 
+   ZOOKEEPER-222.  print C client log message timestamp in human readable
+form. (pat via mahadev) 
+
 Release 3.0.0 - 2008-10-21
 
 Non-backward compatible changes:

Modified: hadoop/zookeeper/trunk/src/c/src/zk_log.c
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/c/src/zk_log.c?rev=726862&r1=726861&r2=726862&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/src/c/src/zk_log.c (original)
+++ hadoop/zookeeper/trunk/src/c/src/zk_log.c Mon Dec 15 14:36:25 2008
@@ -23,8 +23,9 @@
 #include "zk_log.h"
 #include <unistd.h>
 #include <stdarg.h>
+#include <time.h>
 
-#define TIME_NOW_BUF_SIZE 128
+#define TIME_NOW_BUF_SIZE 1024
 #define FORMAT_LOG_BUF_SIZE 2048
 
 #ifdef THREADED
@@ -95,7 +96,24 @@
         return "time_now(): Failed to allocate memory buffer";
     
     gettimeofday(&tv,0);
-    sprintf(now_str,"%ld.%03d.%03d",tv.tv_sec,(int)(tv.tv_usec/1000),(int)(tv.tv_usec%1000));
+
+    const time_t now = tv.tv_sec;
+    struct tm lt;
+    localtime_r(&now, &lt);
+
+    // clone the format used by log4j ISO8601DateFormat
+    // specifically: "yyyy-MM-dd HH:mm:ss,SSS"
+
+    size_t len = strftime(now_str,
+                          TIME_NOW_BUF_SIZE,
+                          "%F %H:%M:%S",
+                          &lt);
+
+    len += snprintf(now_str + len,
+                    TIME_NOW_BUF_SIZE - len,
+                    ",%03d",
+                    (int)(tv.tv_usec/1000));
+
     return now_str;
 }
 



Mime
View raw message