[Spice-commits] 3 commits - common/vdlog.cpp common/vdlog.h

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Sun Jul 8 19:20:55 UTC 2018


 common/vdlog.cpp |   23 +++++++++++++++++++++++
 common/vdlog.h   |   28 +++++++++++-----------------
 2 files changed, 34 insertions(+), 17 deletions(-)

New commits:
commit 9ddddf205f61b3451f37867a3bf7db455c773e53
Author: Frediano Ziglio <fziglio at redhat.com>
Date:   Tue May 29 01:01:23 2018 +0100

    vdlog: Use GetLocalTime instead of multiple C functions
    
    The GetLocalTime function already returns all information we
    need for the log, no needs to call multiple C functions.
    
    Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
    Acked-by: Jonathon Jongsma <jjongsma at redhat.com>

diff --git a/common/vdlog.cpp b/common/vdlog.cpp
index 8c11d33..e2561e2 100644
--- a/common/vdlog.cpp
+++ b/common/vdlog.cpp
@@ -84,18 +84,15 @@ void VDLog::logf(const char *type, const char *function, const char* format, ...
     FILE *fh = _log ? _log->_handle : stdout;
     va_list args;
 
-    struct _timeb now;
-    struct tm today;
-    char datetime_str[20];
-    _ftime_s(&now);
-    localtime_s(&today, &now.time);
-    strftime(datetime_str, 20, "%Y-%m-%d %H:%M:%S", &today);
+    SYSTEMTIME st;
+    GetLocalTime(&st);
 
     _lock_file(fh);
-    fprintf(fh, "%lu::%s::%s,%.3d::%s::",
+    fprintf(fh, "%lu::%s::%.4u-%.2u-%.2u %.2u:%.2u:%.2u,%.3u::%s::",
             GetCurrentThreadId(), type,
-            datetime_str,
-            now.millitm,
+            st.wYear, st.wMonth, st.wDay,
+            st.wHour, st.wMinute, st.wSecond,
+            st.wMilliseconds,
             function);
 
     va_start(args, format);
commit df20de186c5a014c4064a4f6e57bd53493c37348
Author: Frediano Ziglio <fziglio at redhat.com>
Date:   Tue May 29 01:01:23 2018 +0100

    vdlog: Factor our a "logf" function to avoid long "LOG" macro
    
    Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
    Acked-by: Jonathon Jongsma <jjongsma at redhat.com>

diff --git a/common/vdlog.cpp b/common/vdlog.cpp
index 8af6dcc..8c11d33 100644
--- a/common/vdlog.cpp
+++ b/common/vdlog.cpp
@@ -79,6 +79,32 @@ void VDLog::printf(const char* format, ...)
     fflush(fh);
 }
 
+void VDLog::logf(const char *type, const char *function, const char* format, ...)
+{
+    FILE *fh = _log ? _log->_handle : stdout;
+    va_list args;
+
+    struct _timeb now;
+    struct tm today;
+    char datetime_str[20];
+    _ftime_s(&now);
+    localtime_s(&today, &now.time);
+    strftime(datetime_str, 20, "%Y-%m-%d %H:%M:%S", &today);
+
+    _lock_file(fh);
+    fprintf(fh, "%lu::%s::%s,%.3d::%s::",
+            GetCurrentThreadId(), type,
+            datetime_str,
+            now.millitm,
+            function);
+
+    va_start(args, format);
+    vfprintf(fh, format, args);
+    va_end(args);
+    _unlock_file(fh);
+    fflush(fh);
+}
+
 void log_version()
 {
     // print same version as resource one
diff --git a/common/vdlog.h b/common/vdlog.h
index d017ac3..c80a199 100644
--- a/common/vdlog.h
+++ b/common/vdlog.h
@@ -35,6 +35,10 @@ public:
     __attribute__((__format__ (gnu_printf, 1, 2)))
 #endif
     static void printf(const char* format, ...);
+#ifdef __GNUC__
+    __attribute__((__format__ (gnu_printf, 3, 4)))
+#endif
+    static void logf(const char *type, const char *function, const char* format, ...);
 
 private:
     VDLog(FILE* handle);
@@ -60,16 +64,7 @@ static const VDLogLevel log_level = LOG_INFO;
 
 #define LOG(type, format, ...) do {                                     \
     if (LOG_ ## type >= log_level && LOG_ ## type <= LOG_FATAL) {       \
-        struct _timeb now;                                              \
-        struct tm today;                                                \
-        char datetime_str[20];                                          \
-        _ftime_s(&now);                                                 \
-        localtime_s(&today, &now.time);                                 \
-        strftime(datetime_str, 20, "%Y-%m-%d %H:%M:%S", &today);        \
-        VDLog::printf("%lu::%s::%s,%.3d::%s::" format "\n",             \
-                      GetCurrentThreadId(), #type,                      \
-                      datetime_str, now.millitm,                        \
-                      __FUNCTION__, ## __VA_ARGS__);                    \
+        VDLog::logf(#type, __FUNCTION__, format "\n", ## __VA_ARGS__);  \
     }                                                                   \
 } while(0)
 
commit c4b8c5349e3870cde0101e890e6aeb7f78bc89e2
Author: Frediano Ziglio <fziglio at redhat.com>
Date:   Sun Jul 1 06:50:58 2018 +0100

    vdlog: Remove the lookup table for log types
    
    As log type is passed as constant in some macros and the lockup
    is basically using this name without the prefix pass to the macro
    the name without the prefix.
    
    Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
    Acked-by: Jonathon Jongsma <jjongsma at redhat.com>

diff --git a/common/vdlog.h b/common/vdlog.h
index 9f08fc4..d017ac3 100644
--- a/common/vdlog.h
+++ b/common/vdlog.h
@@ -59,8 +59,7 @@ static const VDLogLevel log_level = LOG_INFO;
 #endif
 
 #define LOG(type, format, ...) do {                                     \
-    if (type >= log_level && type <= LOG_FATAL) {                       \
-        const char *type_as_char[] = { "DEBUG", "INFO", "WARN", "ERROR", "FATAL" }; \
+    if (LOG_ ## type >= log_level && LOG_ ## type <= LOG_FATAL) {       \
         struct _timeb now;                                              \
         struct tm today;                                                \
         char datetime_str[20];                                          \
@@ -68,23 +67,23 @@ static const VDLogLevel log_level = LOG_INFO;
         localtime_s(&today, &now.time);                                 \
         strftime(datetime_str, 20, "%Y-%m-%d %H:%M:%S", &today);        \
         VDLog::printf("%lu::%s::%s,%.3d::%s::" format "\n",             \
-                      GetCurrentThreadId(), type_as_char[type],         \
+                      GetCurrentThreadId(), #type,                      \
                       datetime_str, now.millitm,                        \
                       __FUNCTION__, ## __VA_ARGS__);                    \
     }                                                                   \
 } while(0)
 
 
-#define vd_printf(format, ...) LOG(LOG_INFO, format, ## __VA_ARGS__)
-#define LOG_INFO(format, ...) LOG(LOG_INFO, format, ## __VA_ARGS__)
-#define LOG_WARN(format, ...) LOG(LOG_WARN, format, ## __VA_ARGS__)
-#define LOG_ERROR(format, ...) LOG(LOG_ERROR, format, ## __VA_ARGS__)
+#define vd_printf(format, ...) LOG(INFO, format, ## __VA_ARGS__)
+#define LOG_INFO(format, ...) LOG(INFO, format, ## __VA_ARGS__)
+#define LOG_WARN(format, ...) LOG(WARN, format, ## __VA_ARGS__)
+#define LOG_ERROR(format, ...) LOG(ERROR, format, ## __VA_ARGS__)
 
 #define DBGLEVEL 1000
 
 #define DBG(level, format, ...) do {            \
     if (level <= DBGLEVEL) {                    \
-        LOG(LOG_DEBUG, format, ## __VA_ARGS__); \
+        LOG(DEBUG, format, ## __VA_ARGS__);     \
     }                                           \
 } while(0)
 


More information about the Spice-commits mailing list