[Spice-devel] [PATCH] client: log formatted time (#674013)

Uri Lublin uril at redhat.com
Mon May 30 08:57:21 PDT 2011


---
 client/application.cpp |   16 ++++++++++++++--
 1 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/client/application.cpp b/client/application.cpp
index 606f7e2..85a4804 100644
--- a/client/application.cpp
+++ b/client/application.cpp
@@ -2496,12 +2496,23 @@ static inline std::string function_to_func_name(const std::string& f_name)
 #endif
 }

+void get_timestamp(char *buff, int buffsize)
+{
+    time_t      t;
+    struct tm   *tm;
+
+    t = time(NULL);
+    tm = localtime(&t);
+    strftime(buff, buffsize, "%y-%m-%d %H:%m:%S", tm);
+}
+
 void spice_log(unsigned int type, const char *function, const char *format, ...)
 {
     std::string formated_message;
     va_list ap;
     const char *type_as_char[] = { "DEBUG", "INFO", "WARN", "ERROR", "FATAL" };
     const char *type_as_nice_char[] = { "Debug", "Info", "Warning", "Error", "Fatal error" };
+    char ts[32];

     if (type < log_level) {
       return;
@@ -2513,9 +2524,10 @@ void spice_log(unsigned int type, const char *function, const char *format, ...)
     string_vprintf(formated_message, format, ap);
     va_end(ap);

+    get_timestamp(ts, sizeof(ts));
     if (type >= log_level && log_file != NULL) {
-        fprintf(log_file,"%ld %s [%" PRIu64 ":%" PRIu64 "] %s: %s\n",
-                (long)time(NULL), type_as_char[type],
+        fprintf(log_file,"%s %s [%" PRIu64 ":%" PRIu64 "] %s: %s\n",
+                ts, type_as_char[type],
                 Platform::get_process_id(),
                 Platform::get_thread_id(),
                 function_to_func_name(function).c_str(),
-- 
1.7.4.4



More information about the Spice-devel mailing list