16#include <glib/gprintf.h>
23#define IMQUIC_MAX_VARINT (((uint64_t)1 << 62) - 1)
28#define IMQUIC_ANSI_COLOR_RED "\x1b[31m"
29#define IMQUIC_ANSI_COLOR_GREEN "\x1b[32m"
30#define IMQUIC_ANSI_COLOR_YELLOW "\x1b[33m"
31#define IMQUIC_ANSI_COLOR_BLUE "\x1b[34m"
32#define IMQUIC_ANSI_COLOR_MAGENTA "\x1b[35m"
33#define IMQUIC_ANSI_COLOR_CYAN "\x1b[36m"
34#define IMQUIC_ANSI_COLOR_RESET "\x1b[0m"
41#define IMQUIC_LOG_NONE (0)
43#define IMQUIC_LOG_FATAL (1)
45#define IMQUIC_LOG_ERR (2)
47#define IMQUIC_LOG_WARN (3)
49#define IMQUIC_LOG_INFO (4)
51#define IMQUIC_LOG_VERB (5)
53#define IMQUIC_LOG_HUGE (6)
55#define IMQUIC_LOG_DBG (7)
57#define IMQUIC_LOG_MAX IMQUIC_LOG_DBG
59#pragma GCC diagnostic push
60#pragma GCC diagnostic ignored "-Wunused-variable"
62static const char *imquic_log_prefix[] = {
83#pragma GCC diagnostic pop
89#define IMQUIC_PRINT(format, ...) \
91 if(imquic_log_function == NULL) { \
95 imquic_log_function(IMQUIC_LOG_NONE, format, \
102#define IMQUIC_LOG(level, format, ...) \
104 if (level > IMQUIC_LOG_NONE && level <= IMQUIC_LOG_MAX && level <= imquic_log_level) { \
105 if(imquic_log_function == NULL) { \
106 char imquic_log_ts[64] = ""; \
107 char imquic_log_src[128] = ""; \
108 if (imquic_log_timestamps) { \
109 struct tm imquictmresult; \
110 time_t imquicltime = time(NULL); \
111 localtime_r(&imquicltime, &imquictmresult); \
112 strftime(imquic_log_ts, sizeof(imquic_log_ts), \
113 "[%a %b %e %T %Y] ", &imquictmresult); \
115 if (level == IMQUIC_LOG_FATAL || level == IMQUIC_LOG_ERR || level == IMQUIC_LOG_DBG) { \
116 snprintf(imquic_log_src, sizeof(imquic_log_src), \
117 "[%s:%s:%d] ", __FILE__, __FUNCTION__, __LINE__); \
119 g_print("%s%s%s" format, \
121 imquic_log_prefix[level | ((int)imquic_log_colors << 3)], \
125 imquic_log_function(level, format, \
#define IMQUIC_ANSI_COLOR_RESET
Definition debug.h:34
#define IMQUIC_ANSI_COLOR_YELLOW
Definition debug.h:30
#define IMQUIC_ANSI_COLOR_MAGENTA
Definition debug.h:32
#define IMQUIC_ANSI_COLOR_RED
Definition debug.h:28
int imquic_log_level
Definition imquic.c:26
gboolean imquic_log_timestamps
Definition imquic.c:27
gboolean imquic_log_colors
Definition imquic.c:29
void(* imquic_log_function)(int level, const char *format,...)
Definition imquic.c:28