Loading...
Searching...
No Matches
debug.h
Go to the documentation of this file.
1
10#ifndef IMQUIC_DEBUG_H
11#define IMQUIC_DEBUG_H
12
13#include <inttypes.h>
14
15#include <glib.h>
16#include <glib/gprintf.h>
17
18extern int imquic_log_level;
19extern gboolean imquic_log_timestamps;
20extern gboolean imquic_log_colors;
21
22#define IMQUIC_MAX_VARINT (((uint64_t)1 << 62) - 1)
23
27#define IMQUIC_ANSI_COLOR_RED "\x1b[31m"
28#define IMQUIC_ANSI_COLOR_GREEN "\x1b[32m"
29#define IMQUIC_ANSI_COLOR_YELLOW "\x1b[33m"
30#define IMQUIC_ANSI_COLOR_BLUE "\x1b[34m"
31#define IMQUIC_ANSI_COLOR_MAGENTA "\x1b[35m"
32#define IMQUIC_ANSI_COLOR_CYAN "\x1b[36m"
33#define IMQUIC_ANSI_COLOR_RESET "\x1b[0m"
35
39
40#define IMQUIC_LOG_NONE (0)
42#define IMQUIC_LOG_FATAL (1)
44#define IMQUIC_LOG_ERR (2)
46#define IMQUIC_LOG_WARN (3)
48#define IMQUIC_LOG_INFO (4)
50#define IMQUIC_LOG_VERB (5)
52#define IMQUIC_LOG_HUGE (6)
54#define IMQUIC_LOG_DBG (7)
56#define IMQUIC_LOG_MAX IMQUIC_LOG_DBG
57
58#pragma GCC diagnostic push
59#pragma GCC diagnostic ignored "-Wunused-variable"
61static const char *imquic_log_prefix[] = {
62/* no colors */
63 "",
64 "[FATAL] ",
65 "[ERR] ",
66 "[WARN] ",
67 "",
68 "",
69 "",
70 "",
71/* with colors */
72 "",
76 "",
77 "",
78 "",
79 ""
80};
82#pragma GCC diagnostic pop
83
87
88#define IMQUIC_PRINT g_print
92#define IMQUIC_LOG(level, format, ...) \
93do { \
94 if (level > IMQUIC_LOG_NONE && level <= IMQUIC_LOG_MAX && level <= imquic_log_level) { \
95 char imquic_log_ts[64] = ""; \
96 char imquic_log_src[128] = ""; \
97 if (imquic_log_timestamps) { \
98 struct tm imquictmresult; \
99 time_t imquicltime = time(NULL); \
100 localtime_r(&imquicltime, &imquictmresult); \
101 strftime(imquic_log_ts, sizeof(imquic_log_ts), \
102 "[%a %b %e %T %Y] ", &imquictmresult); \
103 } \
104 if (level == IMQUIC_LOG_FATAL || level == IMQUIC_LOG_ERR || level == IMQUIC_LOG_DBG) { \
105 snprintf(imquic_log_src, sizeof(imquic_log_src), \
106 "[%s:%s:%d] ", __FILE__, __FUNCTION__, __LINE__); \
107 } \
108 g_print("%s%s%s" format, \
109 imquic_log_ts, \
110 imquic_log_prefix[level | ((int)imquic_log_colors << 3)], \
111 imquic_log_src, \
112 ##__VA_ARGS__); \
113 } \
114} while (0)
116
117#endif
#define IMQUIC_ANSI_COLOR_RESET
Definition debug.h:33
#define IMQUIC_ANSI_COLOR_YELLOW
Definition debug.h:29
#define IMQUIC_ANSI_COLOR_MAGENTA
Definition debug.h:31
#define IMQUIC_ANSI_COLOR_RED
Definition debug.h:27
int imquic_log_level
Definition imquic.c:27
gboolean imquic_log_timestamps
Definition imquic.c:28
gboolean imquic_log_colors
Definition imquic.c:29