Loading...
Searching...
No Matches
debug.h
Go to the documentation of this file.
#ifndef JANUS_DEBUG_H
#define JANUS_DEBUG_H
#include <glib.h>
#include <glib/gprintf.h>
#include "log.h"
extern int janus_log_level;
extern gboolean janus_log_timestamps;
extern gboolean janus_log_colors;
extern char *janus_log_global_prefix;
#define ANSI_COLOR_RED "\x1b[31m"
#define ANSI_COLOR_GREEN "\x1b[32m"
#define ANSI_COLOR_YELLOW "\x1b[33m"
#define ANSI_COLOR_BLUE "\x1b[34m"
#define ANSI_COLOR_MAGENTA "\x1b[35m"
#define ANSI_COLOR_CYAN "\x1b[36m"
#define ANSI_COLOR_RESET "\x1b[0m"
#define LOG_NONE (0)
#define LOG_FATAL (1)
#define LOG_ERR (2)
#define LOG_WARN (3)
#define LOG_INFO (4)
#define LOG_VERB (5)
#define LOG_HUGE (6)
#define LOG_DBG (7)
#define LOG_MAX LOG_DBG
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-variable"
static const char *janus_log_prefix[] = {
/* no colors */
"",
"[FATAL] ",
"[ERR] ",
"[WARN] ",
"",
"",
"",
"",
/* with colors */
"",
ANSI_COLOR_MAGENTA "[FATAL]" ANSI_COLOR_RESET " ",
ANSI_COLOR_RED "[ERR]" ANSI_COLOR_RESET " ",
ANSI_COLOR_YELLOW "[WARN]" ANSI_COLOR_RESET " ",
"",
"",
"",
""
};
#pragma GCC diagnostic pop
#define JANUS_PRINT janus_vprintf
#define JANUS_LOG(level, format, ...) \
do { \
if (level > LOG_NONE && level <= LOG_MAX && level <= janus_log_level) { \
char janus_log_ts[64] = ""; \
char janus_log_src[128] = ""; \
if (janus_log_timestamps) { \
struct tm janustmresult; \
time_t janusltime = time(NULL); \
localtime_r(&janusltime, &janustmresult); \
strftime(janus_log_ts, sizeof(janus_log_ts), \
"[%a %b %e %T %Y] ", &janustmresult); \
} \
if (level == LOG_FATAL || level == LOG_ERR || level == LOG_DBG) { \
snprintf(janus_log_src, sizeof(janus_log_src), \
"[%s:%s:%d] ", __FILE__, __FUNCTION__, __LINE__); \
} \
JANUS_PRINT("%s%s%s%s" format, \
janus_log_global_prefix ? janus_log_global_prefix : "", \
janus_log_ts, \
janus_log_prefix[level | ((int)janus_log_colors << 3)], \
janus_log_src, \
##__VA_ARGS__); \
} \
} while (0)
#endif
janus_log_level
int janus_log_level
Definition janus-cfgconv.c:34
janus_log_timestamps
gboolean janus_log_timestamps
Definition janus-cfgconv.c:35
ANSI_COLOR_RED
#define ANSI_COLOR_RED
Definition debug.h:26
ANSI_COLOR_YELLOW
#define ANSI_COLOR_YELLOW
Definition debug.h:28
ANSI_COLOR_RESET
#define ANSI_COLOR_RESET
Definition debug.h:32
janus_log_colors
gboolean janus_log_colors
Definition janus-cfgconv.c:36
ANSI_COLOR_MAGENTA
#define ANSI_COLOR_MAGENTA
Definition debug.h:30
janus_log_global_prefix
char * janus_log_global_prefix
Definition janus-cfgconv.c:37
log.h
Buffered logging (headers)