[Spice-devel] [PATCH vdagent-win 3/3] vdlog: change log times to human readable date & time rhbz#672828

Arnon Gilboa agilboa at redhat.com
Wed Nov 16 02:16:37 PST 2011


ifndef USE_DATE_TIME, use system time instead of secs from system startup
---
 common/vdlog.h |   23 ++++++++++++++++++++---
 1 files changed, 20 insertions(+), 3 deletions(-)

diff --git a/common/vdlog.h b/common/vdlog.h
index bb2eb28..995e9d3 100644
--- a/common/vdlog.h
+++ b/common/vdlog.h
@@ -22,8 +22,10 @@
 #include <tchar.h>
 #include <crtdbg.h>
 #include <windows.h>
+#include <time.h>
 
 #define LOG_ENABLED
+#define USE_DATE_TIME
 
 class VDLog {
 public:
@@ -40,15 +42,30 @@ private:
 };
 
 #ifdef LOG_ENABLED
+
+#ifndef USE_DATE_TIME
+#define vd_printf(format, ...) {                                                    \
+    VDLog* log = VDLog::get();                                                      \
+    if (log) {                                                                      \
+        log->printf("%ld %s: " format "\n", _time64(NULL), __FUNCTION__, __VA_ARGS__);  \
+    } else {                                                                        \
+        printf("%ld %s: " format "\n", _time64(NULL), __FUNCTION__, __VA_ARGS__);       \
+    }                                                                               \
+}
+#else
 #define vd_printf(format, ...) {                                                    \
     VDLog* log = VDLog::get();                                                      \
-    double secs = GetTickCount() / 1000.0;                                          \
+    char date_str[9];                                                               \
+    char time_str[9];                                                               \
+    _strdate_s(date_str, sizeof(date_str));                                         \
+    _strtime_s(time_str, sizeof(time_str));                                         \
     if (log) {                                                                      \
-        log->printf("%.3f %s: " format "\n", secs, __FUNCTION__, __VA_ARGS__);      \
+        log->printf("%s %s %s: " format "\n", date_str, time_str, __FUNCTION__, __VA_ARGS__);   \
     } else {                                                                        \
-        printf("%.3f %s: " format "\n", secs, __FUNCTION__, __VA_ARGS__);           \
+        printf("%s %s %s: " format "\n", date_str, time_str, __FUNCTION__, __VA_ARGS__);        \
     }                                                                               \
 }
+#endif //USE_DATE_TIME
 
 #define ASSERT(x) _ASSERTE(x)
 #else
-- 
1.7.4.1



More information about the Spice-devel mailing list