Fork me on GitHub
Loading...
Searching...
No Matches
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
18extern int janus_log_level;
19extern gboolean janus_log_timestamps;
20extern gboolean janus_log_colors;
21extern char *janus_log_global_prefix;
22
26#define ANSI_COLOR_RED "\x1b[31m"
27#define ANSI_COLOR_GREEN "\x1b[32m"
28#define ANSI_COLOR_YELLOW "\x1b[33m"
29#define ANSI_COLOR_BLUE "\x1b[34m"
30#define ANSI_COLOR_MAGENTA "\x1b[35m"
31#define ANSI_COLOR_CYAN "\x1b[36m"
32#define ANSI_COLOR_RESET "\x1b[0m"
34
38
39#define LOG_NONE (0)
41#define LOG_FATAL (1)
43#define LOG_ERR (2)
45#define LOG_WARN (3)
47#define LOG_INFO (4)
49#define LOG_VERB (5)
51#define LOG_HUGE (6)
53#define LOG_DBG (7)
55#define LOG_MAX LOG_DBG
56
57#pragma GCC diagnostic push
58#pragma GCC diagnostic ignored "-Wunused-variable"
60static const char *janus_log_prefix[] = {
61/* no colors */
62 "",
63 "[FATAL] ",
64 "[ERR] ",
65 "[WARN] ",
66 "",
67 "",
68 "",
69 "",
70/* with colors */
71 "",
75 "",
76 "",
77 "",
78 ""
79};
81#pragma GCC diagnostic pop
82
86
87#define JANUS_PRINT janus_vprintf
91#define JANUS_LOG(level, format, ...) \
92do { \
93 if (level > LOG_NONE && level <= LOG_MAX && level <= janus_log_level) { \
94 char janus_log_ts[64] = ""; \
95 char janus_log_src[128] = ""; \
96 if (janus_log_timestamps) { \
97 struct tm janustmresult; \
98 time_t janusltime = time(NULL); \
99 localtime_r(&janusltime, &janustmresult); \
100 strftime(janus_log_ts, sizeof(janus_log_ts), \
101 "[%a %b %e %T %Y] ", &janustmresult); \
102 } \
103 if (level == LOG_FATAL || level == LOG_ERR || level == LOG_DBG) { \
104 snprintf(janus_log_src, sizeof(janus_log_src), \
105 "[%s:%s:%d] ", __FILE__, __FUNCTION__, __LINE__); \
106 } \
107 JANUS_PRINT("%s%s%s%s" format, \
108 janus_log_global_prefix ? janus_log_global_prefix : "", \
109 janus_log_ts, \
110 janus_log_prefix[level | ((int)janus_log_colors << 3)], \
111 janus_log_src, \
112 ##__VA_ARGS__); \
113 } \
114} while (0)
116
117#endif
int janus_log_level
Definition: janus-cfgconv.c:34
gboolean janus_log_timestamps
Definition: janus-cfgconv.c:35
#define ANSI_COLOR_RED
Definition: debug.h:26
#define ANSI_COLOR_YELLOW
Definition: debug.h:28
#define ANSI_COLOR_RESET
Definition: debug.h:32
gboolean janus_log_colors
Definition: janus-cfgconv.c:36
#define ANSI_COLOR_MAGENTA
Definition: debug.h:30
char * janus_log_global_prefix
Definition: janus-cfgconv.c:37
Buffered logging (headers)