]> git.itanic.dy.fi Git - rrdd/blob - debug.h
Autoindent debug messages according to parent count
[rrdd] / debug.h
1 #ifndef __DEBUG_H
2 #define __DEBUG_H
3
4 #include <unistd.h>
5 #include "process.h"
6
7 extern const char red_color[];
8 extern const char green_color[];
9 extern const char normal_color[];
10
11 #define pr_info(fmt, arg...)                                            \
12         do {                                                            \
13                 char indent[16] = { ' ' };                              \
14                 indent[get_parent_count()] = 0;                         \
15                 fprintf(stderr, "%s%s[%d] %s:%d %s"                     \
16                         fmt, indent, green_color, getpid(),             \
17                         __FILE__, __LINE__, normal_color, ##arg);       \
18         } while (0)
19
20
21 #define pr_err(fmt, arg...)                                             \
22         do {                                                            \
23                 char indent[16] = { ' ' };                              \
24                 indent[get_parent_count()] = 0;                         \
25                 fprintf(stderr, "%s%s[%d] %s:%d Error %s"               \
26                         fmt, indent, red_color, getpid(),               \
27                         __FILE__, __LINE__, normal_color, ##arg);       \
28         } while (0)
29
30 #endif