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

Submitted by Uri Lublin on July 20, 2011, 5:03 p.m.

Details

Message ID 1311156222-3062-1-git-send-email-uril@redhat.com
State New, archived
Headers show

Not browsing as part of any series.

Commit Message

Uri Lublin July 20, 2011, 5:03 p.m.
V2 changes:
  moved get_timestamp into the if() condition.
  initialize ts[0]='\0' before calling get_timestamp.

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

Patch hide | download patch | download mbox

diff --git a/client/application.cpp b/client/application.cpp
index 606f7e2..f628b40 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;
@@ -2514,8 +2525,10 @@  void spice_log(unsigned int type, const char *function, const char *format, ...)
     va_end(ap);

     if (type >= log_level && log_file != NULL) {
-        fprintf(log_file,"%ld %s [%" PRIu64 ":%" PRIu64 "] %s: %s\n",
-                (long)time(NULL), type_as_char[type],
+        ts[0] = '\0';
+        get_timestamp(ts, sizeof(ts));
+        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(),