[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[master] logging: refactor printLogHeader



From: Ales Kozumplik <akozumpl redhat com>

---
 pyanaconda/isys/log.c |   39 +++++++++++++--------------------------
 pyanaconda/isys/log.h |    1 +
 2 files changed, 14 insertions(+), 26 deletions(-)

diff --git a/pyanaconda/isys/log.c b/pyanaconda/isys/log.c
index 96da57e..0421684 100644
--- a/pyanaconda/isys/log.c
+++ b/pyanaconda/isys/log.c
@@ -27,6 +27,7 @@
 #include <stdarg.h>
 #include <stdio.h>
 #include <stdlib.h>
+#include <string.h>
 #include <time.h>
 #include <unistd.h>
 #include <sys/time.h>
@@ -62,40 +63,26 @@ static int mapLogLevel(int level)
     }
 }
 
+const char *log_level_to_str[LOGLEVEL_MAX + 1] = {
+    [DEBUGLVL] = "DEBUG",
+    [INFO] = "INFO",
+    [WARNING] = "WARN",
+    [ERROR] = "ERR",
+    [CRITICAL] = "CRIT"
+};
+
 static void printLogHeader(int level, const char *tag, FILE *outfile) {
     struct timeval current_time;
     struct tm *t;
     int msecs;
+    const char *level_name;
 
     gettimeofday(&current_time, NULL);
     t = gmtime(&current_time.tv_sec);
     msecs = current_time.tv_usec / 1000;
-    switch (level) {
-        case DEBUGLVL:
-            fprintf (outfile, "%02d:%02d:%02d,%03d DEBUG %s: ", t->tm_hour,
-                     t->tm_min, t->tm_sec, msecs, tag);
-            break;
-
-        case INFO:
-            fprintf (outfile, "%02d:%02d:%02d,%03d INFO %s: ", t->tm_hour,
-                     t->tm_min, t->tm_sec, msecs, tag);
-            break;
-
-        case WARNING:
-            fprintf (outfile, "%02d:%02d:%02d,%03d WARN %s: ", t->tm_hour,
-                     t->tm_min, t->tm_sec, msecs, tag);
-            break;
-
-        case ERROR:
-            fprintf (outfile, "%02d:%02d:%02d,%03d ERR %s: ", t->tm_hour,
-                     t->tm_min, t->tm_sec, msecs, tag);
-            break;
-
-        case CRITICAL:
-            fprintf (outfile, "%02d:%02d:%02d,%03d CRIT %s: ", t->tm_hour,
-                     t->tm_min, t->tm_sec, msecs, tag);
-            break;
-    }
+    level_name = log_level_to_str[level];
+    fprintf(outfile, "%02d:%02d:%02d,%03d %s %s: ", t->tm_hour,
+            t->tm_min, t->tm_sec, msecs, level_name, tag);
 }
 
 static void printLogMessage(int level, const char *tag, FILE *outfile, const char *s, va_list ap)
diff --git a/pyanaconda/isys/log.h b/pyanaconda/isys/log.h
index 88d0010..910fd9a 100644
--- a/pyanaconda/isys/log.h
+++ b/pyanaconda/isys/log.h
@@ -28,6 +28,7 @@
 #define WARNING  30
 #define ERROR    40
 #define CRITICAL 50
+#define LOGLEVEL_MAX CRITICAL
 
 enum logger_t {
     MAIN_LOG = 1,
-- 
1.7.1.1


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]