]> git.itanic.dy.fi Git - rrdd/blobdiff - debug.c
onewire_parser.c: Fix compiler warnings about string lengths
[rrdd] / debug.c
diff --git a/debug.c b/debug.c
index 55fdd14937c8dd9d7080584b60a093412e5d5bef..201f7ef2d1a233cdaa70e877bee2fdaf19448224 100644 (file)
--- a/debug.c
+++ b/debug.c
@@ -4,8 +4,9 @@
 #include <time.h>
 #include <unistd.h>
 #include <stdarg.h>
-#include "process.h"
+#include <pthread.h>
 
+#include "process.h"
 #include "debug.h"
 
 const char red_color[] = {
@@ -20,8 +21,8 @@ const char normal_color[] = {
        0x1b, 0x5b, 0x30, 0x3b, 0x33, 0x37, 0x3b, 0x34, 0x30, 0x6d, 0x0,
 };
 
-int trace_level = 1;
-int logfile_fd = STDERR_FILENO;
+int trace_level = TRACE_INFO;
+static int logfile_fd = STDERR_FILENO;
 
 static const char *assign_color(int color)
 {
@@ -31,7 +32,7 @@ static const char *assign_color(int color)
        case 2:
                return green_color;
        default:
-               return normal_color;
+       return normal_color;
        }
 }
 
@@ -43,6 +44,7 @@ void print_trace(const char *file, int line, int color, int l,
        char time[32];
        char trace[1024];
        char all_trace[1538];
+       char thread_name[16];
        const char *color_str = assign_color(color);
        int ret;
 
@@ -55,10 +57,12 @@ void print_trace(const char *file, int line, int color, int l,
 
        strftime(time, sizeof(time), "%d.%m.%Y %T", localtime(&t));
 
+       pthread_getname_np(pthread_self(), thread_name, sizeof(thread_name));
+
        ret = snprintf(all_trace, sizeof(all_trace),
-               "%s%s [%5d.%d] %s:%d %s %s",
+               "%s%s [%s] %s:%d %s %s",
                color_str, time,
-               getpid(), get_parent_count(),
+               thread_name,
                file, line, normal_color, trace);
 
        ret = write(logfile_fd, all_trace, ret);