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
25#define IMQUIC_ANSI_COLOR_RED "\x1b[31m"
26#define IMQUIC_ANSI_COLOR_GREEN "\x1b[32m"
27#define IMQUIC_ANSI_COLOR_YELLOW "\x1b[33m"
28#define IMQUIC_ANSI_COLOR_BLUE "\x1b[34m"
29#define IMQUIC_ANSI_COLOR_MAGENTA "\x1b[35m"
30#define IMQUIC_ANSI_COLOR_CYAN "\x1b[36m"
31#define IMQUIC_ANSI_COLOR_RESET "\x1b[0m"
33
37
38#define IMQUIC_LOG_NONE (0)
40#define IMQUIC_LOG_FATAL (1)
42#define IMQUIC_LOG_ERR (2)
44#define IMQUIC_LOG_WARN (3)
46#define IMQUIC_LOG_INFO (4)
48#define IMQUIC_LOG_VERB (5)
50#define IMQUIC_LOG_HUGE (6)
52#define IMQUIC_LOG_DBG (7)
54#define IMQUIC_LOG_MAX IMQUIC_LOG_DBG
55
56#pragma GCC diagnostic push
57#pragma GCC diagnostic ignored "-Wunused-variable"
59static const char *imquic_log_prefix[] = {
60/* no colors */
61 "",
62 "[FATAL] ",
63 "[ERR] ",
64 "[WARN] ",
65 "",
66 "",
67 "",
68 "",
69/* with colors */
70 "",
74 "",
75 "",
76 "",
77 ""
78};
80#pragma GCC diagnostic pop
81
85
86#define IMQUIC_PRINT g_print
90#define IMQUIC_LOG(level, format, ...) \
91do { \
92 if (level > IMQUIC_LOG_NONE && level <= IMQUIC_LOG_MAX && level <= imquic_log_level) { \
93 char imquic_log_ts[64] = ""; \
94 char imquic_log_src[128] = ""; \
95 if (imquic_log_timestamps) { \
96 struct tm imquictmresult; \
97 time_t imquicltime = time(NULL); \
98 localtime_r(&imquicltime, &imquictmresult); \
99 strftime(imquic_log_ts, sizeof(imquic_log_ts), \
100 "[%a %b %e %T %Y] ", &imquictmresult); \
101 } \
102 if (level == IMQUIC_LOG_FATAL || level == IMQUIC_LOG_ERR || level == IMQUIC_LOG_DBG) { \
103 snprintf(imquic_log_src, sizeof(imquic_log_src), \
104 "[%s:%s:%d] ", __FILE__, __FUNCTION__, __LINE__); \
105 } \
106 g_print("%s%s%s" format, \
107 imquic_log_ts, \
108 imquic_log_prefix[level | ((int)imquic_log_colors << 3)], \
109 imquic_log_src, \
110 ##__VA_ARGS__); \
111 } \
112} while (0)
114
115#endif
#define IMQUIC_ANSI_COLOR_RESET
Definition debug.h:31
#define IMQUIC_ANSI_COLOR_YELLOW
Definition debug.h:27
#define IMQUIC_ANSI_COLOR_MAGENTA
Definition debug.h:29
#define IMQUIC_ANSI_COLOR_RED
Definition debug.h:25
int imquic_log_level
Definition imquic.c:26
gboolean imquic_log_timestamps
Definition imquic.c:27
gboolean imquic_log_colors
Definition imquic.c:28