[Libvirt-cim] [PATCH V2 2/2] libcmpiutil: add time and thread info in debug log

Wenchao Xia xiawenc at linux.vnet.ibm.com
Mon Dec 17 09:31:05 UTC 2012


  On server we need these information to debug eaiser.

v2:
  format adjusted.

Signed-off-by: Wenchao Xia <xiawenc at linux.vnet.ibm.com>
---
 debug_util.c |   18 +++++++++++++++++-
 1 files changed, 17 insertions(+), 1 deletions(-)

diff --git a/debug_util.c b/debug_util.c
index 2912fb6..0820b9f 100644
--- a/debug_util.c
+++ b/debug_util.c
@@ -23,6 +23,9 @@
 #include <stdlib.h>
 #include <stdarg.h>
 #include <stdio.h>
+#include <pthread.h>
+#include <sys/time.h>
+#include <time.h>
 
 #include "libcmpiutil.h"
 
@@ -32,6 +35,15 @@ static FILE *log = NULL;
 void debug_print(char *fmt, ...)
 {
         char *log_file = NULL;
+        pthread_t id = pthread_self();
+        struct timeval tv;
+        struct timezone tz;
+        gettimeofday(&tv, &tz);
+        time_t timep;
+        struct tm *p;
+        time(&timep);
+        p=localtime(&timep);
+
         va_list ap;
 
         va_start(ap, fmt);
@@ -49,8 +61,12 @@ void debug_print(char *fmt, ...)
                 log_init = 1;
         }
 
-        if (log != NULL)
+        if (log != NULL) {
+                fprintf(log, "[%d-%02d-%02d %02d:%02d:%02d.%06d] [%ld]: ",
+                (1900+p->tm_year), (1+p->tm_mon), p->tm_mday, p->tm_hour,
+                p->tm_min, p->tm_sec, (int)tv.tv_usec, id);
                 vfprintf(log, fmt, ap);
+        }
 
         va_end(ap);
 }
-- 
1.7.1





More information about the Libvirt-cim mailing list