src/ucx/logging.c

branch
config
changeset 254
4784c14aa639
parent 135
471e28cca288
child 260
4779a6fb4fbe
--- a/src/ucx/logging.c	Sun Aug 23 22:02:01 2020 +0200
+++ b/src/ucx/logging.c	Sun Aug 23 23:04:17 2020 +0200
@@ -1,7 +1,7 @@
 /*
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
  *
- * Copyright 2016 Olaf Wintermann. All rights reserved.
+ * Copyright 2017 Mike Becker, Olaf Wintermann All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions are met:
@@ -26,7 +26,8 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 
-#include "logging.h"
+#include "ucx/logging.h"
+
 #include <stdlib.h>
 #include <string.h>
 #include <stdarg.h>
@@ -49,6 +50,8 @@
         ucx_map_int_put(logger->levels, l, (void*) "[WARNING]");
         l = UCX_LOGGER_INFO;
         ucx_map_int_put(logger->levels, l, (void*) "[INFO]");
+        l = UCX_LOGGER_DEBUG;
+        ucx_map_int_put(logger->levels, l, (void*) "[DEBUG]");
         l = UCX_LOGGER_TRACE;
         ucx_map_int_put(logger->levels, l, (void*) "[TRACE]");
     }
@@ -68,12 +71,15 @@
         const unsigned int line, const char *format, ...) {
     if (level <= logger->level) {
         char msg[UCX_LOGGER_MSGMAX];
-        char *text;
+        const char *text;
         size_t k = 0;
         size_t n;
         
         if ((logger->mask & UCX_LOGGER_LEVEL) > 0) {
-            text = (char*) ucx_map_int_get(logger->levels, level);
+            text = (const char*) ucx_map_int_get(logger->levels, level);
+            if (!text) {
+                text = "[UNKNOWN]";
+            }
             n = strlen(text);
             n = n > 256 ? 256 : n;
             memcpy(msg+k, text, n);
@@ -91,7 +97,9 @@
             k += sprintf(msg+k, ":%u ", line);
         }
         
-        msg[k++] = '-'; msg[k++] = ' ';
+        if (k > 0) {
+            msg[k++] = '-'; msg[k++] = ' ';
+        }
         
         va_list args;
         va_start (args, format);

mercurial