]> git.itanic.dy.fi Git - rrdd/blob - debug.h
Merge branch 'master' into itanic
[rrdd] / debug.h
1 #ifndef __DEBUG_H
2 #define __DEBUG_H
3
4 #include <time.h>
5 #include <unistd.h>
6 #include "process.h"
7
8 extern const char red_color[];
9 extern const char green_color[];
10 extern const char normal_color[];
11
12 #define pr_info(fmt, arg...)                                            \
13         do {                                                            \
14                 time_t t = time(0);                                     \
15                 char indent[16] = { "               " };                \
16                 char time[32];                                          \
17                                                                         \
18                 strftime(time, sizeof(time), "%d.%m.%Y %T ",            \
19                         localtime(&t));                                 \
20                 indent[get_parent_count()] = 0;                         \
21                                                                         \
22                 fprintf(stderr, "%s%s %s[%5d.%d] %s:%d %s"              \
23                         fmt, green_color, time, indent,                 \
24                         getpid(), get_parent_count(),                   \
25                         __FILE__, __LINE__, normal_color, ##arg);       \
26                 fflush(stderr);                                         \
27         } while (0)
28
29
30 #define pr_err(fmt, arg...)                                             \
31         do {                                                            \
32                 time_t t = time(0);                                     \
33                 char indent[16] = { "               " };                \
34                 char time[32];                                          \
35                                                                         \
36                 strftime(time, sizeof(time), "%d.%m.%Y %T ",            \
37                         localtime(&t));                                 \
38                 indent[get_parent_count()] = 0;                         \
39                                                                         \
40                 fprintf(stderr, "%s%s %s[%5d.%d] %s:%d Error %s"        \
41                         fmt, red_color, time, indent,                   \
42                         getpid(), get_parent_count(),                   \
43                         __FILE__, __LINE__, normal_color, ##arg);       \
44                 fflush(stderr);                                         \
45         } while (0)
46
47 #endif