Fork me on GitHub
debug.h
Go to the documentation of this file.
1 
11 #ifndef _JANUS_DEBUG_H
12 #define _JANUS_DEBUG_H
13 
14 #include <glib.h>
15 #include <glib/gprintf.h>
16 #include "log.h"
17 
18 extern int janus_log_level;
19 extern gboolean janus_log_timestamps;
20 extern gboolean janus_log_colors;
21 
24 #define ANSI_COLOR_RED "\x1b[31m"
26 #define ANSI_COLOR_GREEN "\x1b[32m"
27 #define ANSI_COLOR_YELLOW "\x1b[33m"
28 #define ANSI_COLOR_BLUE "\x1b[34m"
29 #define ANSI_COLOR_MAGENTA "\x1b[35m"
30 #define ANSI_COLOR_CYAN "\x1b[36m"
31 #define ANSI_COLOR_RESET "\x1b[0m"
32 
36 
38 #define LOG_NONE (0)
39 
40 #define LOG_FATAL (1)
41 
42 #define LOG_ERR (2)
43 
44 #define LOG_WARN (3)
45 
46 #define LOG_INFO (4)
47 
48 #define LOG_VERB (5)
49 
50 #define LOG_HUGE (6)
51 
52 #define LOG_DBG (7)
53 
54 #define LOG_MAX LOG_DBG
55 
57 static const char *janus_log_prefix[] = {
58 /* no colors */
59  "",
60  "[FATAL] ",
61  "[ERR] ",
62  "[WARN] ",
63  "",
64  "",
65  "",
66  "",
67 /* with colors */
68  "",
70  ANSI_COLOR_RED "[ERR]" ANSI_COLOR_RESET " ",
71  ANSI_COLOR_YELLOW "[WARN]" ANSI_COLOR_RESET " ",
72  "",
73  "",
74  "",
75  ""
76 };
78 
81 
83 #define JANUS_PRINT janus_vprintf
84 
87 #define JANUS_LOG(level, format, ...) \
88 do { \
89  if (level > LOG_NONE && level <= LOG_MAX && level <= janus_log_level) { \
90  char janus_log_ts[64] = ""; \
91  char janus_log_src[128] = ""; \
92  if (janus_log_timestamps) { \
93  struct tm janustmresult; \
94  time_t janusltime = time(NULL); \
95  localtime_r(&janusltime, &janustmresult); \
96  strftime(janus_log_ts, sizeof(janus_log_ts), \
97  "[%a %b %e %T %Y] ", &janustmresult); \
98  } \
99  if (level == LOG_FATAL || level == LOG_ERR || level == LOG_DBG) { \
100  snprintf(janus_log_src, sizeof(janus_log_src), \
101  "[%s:%s:%d] ", __FILE__, __FUNCTION__, __LINE__); \
102  } \
103  JANUS_PRINT("%s%s%s" format, \
104  janus_log_ts, \
105  janus_log_prefix[level | ((int)janus_log_colors << 3)], \
106  janus_log_src, \
107  ##__VA_ARGS__); \
108  } \
109 } while (0)
110 
112 #endif
#define ANSI_COLOR_RED
Definition: debug.h:25
#define ANSI_COLOR_YELLOW
Definition: debug.h:27
#define ANSI_COLOR_RESET
Definition: debug.h:31
gboolean janus_log_colors
Definition: janus-cfgconv.c:36
int janus_log_level
Definition: janus-cfgconv.c:34
gboolean janus_log_timestamps
Definition: janus-cfgconv.c:35
#define ANSI_COLOR_MAGENTA
Definition: debug.h:29
Buffered logging (headers)