]> git.itanic.dy.fi Git - rrdd/blob - debug.c
debug.c: Remove indentation from the prints
[rrdd] / debug.c
1 #include <time.h>
2 #include <unistd.h>
3 #include <stdarg.h>
4 #include "process.h"
5
6 #include "debug.h"
7
8 const char red_color[] = {
9         0x1b, 0x5b, 0x30, 0x3b, 0x33, 0x31, 0x3b, 0x34, 0x30, 0x6d, 0x0,
10 };
11
12 const char green_color[] = {
13         0x1b, 0x5b, 0x30, 0x3b, 0x33, 0x32, 0x3b, 0x34, 0x30, 0x6d, 0x0,
14 };
15
16 const char normal_color[] = {
17         0x1b, 0x5b, 0x30, 0x3b, 0x33, 0x37, 0x3b, 0x34, 0x30, 0x6d, 0x0,
18 };
19
20 int trace_level = 1;
21
22 void print_trace(const char *file, int line, int color, int l,
23                 const char *fmt, ...)
24 {
25         va_list args;
26         time_t t = time(0);
27         char time[32];
28         char trace[1024];
29
30         if (l > trace_level)
31                 return;
32
33         va_start(args, fmt);
34         vsnprintf(trace, sizeof(trace), fmt, args);
35         va_end(args);
36
37         strftime(time, sizeof(time), "%d.%m.%Y %T ", localtime(&t));
38
39         fprintf(stderr, "%s%s [%5d.%d] %s:%d %s %s",
40                 green_color, time,
41                 getpid(), get_parent_count(),
42                 file, line, normal_color, trace);
43         fflush(stderr);
44 }