From 1951cca3e1eded52d0406b376eecaeac6e563e3f Mon Sep 17 00:00:00 2001 From: Timo Kokkonen Date: Fri, 30 Nov 2012 18:34:54 +0200 Subject: [PATCH] debug: Improve debugging macros Define different debug levels in one enum list instead of hard coding with magic numbers. Add two new debugging macros, one intended for warning messages and another for pure debugging messages. Signed-off-by: Timo Kokkonen --- debug.c | 6 +++--- debug.h | 14 ++++++++++++-- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/debug.c b/debug.c index 55fdd14..8bc70fc 100644 --- a/debug.c +++ b/debug.c @@ -20,8 +20,8 @@ const char normal_color[] = { 0x1b, 0x5b, 0x30, 0x3b, 0x33, 0x37, 0x3b, 0x34, 0x30, 0x6d, 0x0, }; -int trace_level = 1; -int logfile_fd = STDERR_FILENO; +int trace_level = TRACE_INFO; +static int logfile_fd = STDERR_FILENO; static const char *assign_color(int color) { @@ -31,7 +31,7 @@ static const char *assign_color(int color) case 2: return green_color; default: - return normal_color; + return normal_color; } } diff --git a/debug.h b/debug.h index 1dd11f9..e0f0bc0 100644 --- a/debug.h +++ b/debug.h @@ -5,12 +5,22 @@ extern const char red_color[]; extern const char green_color[]; extern const char normal_color[]; +enum { + TRACE_ERR, + TRACE_WARN, + TRACE_INFO, + TRACE_DEBUG, + TRACE_MAX, +}; + void __attribute__ ((__format__ (__printf__, 5, 6))) print_trace(const char *file, int line, int color, int l, const char *fmt, ...); -#define pr_err(arg...) print_trace(__FILE__, __LINE__, 1, 0, arg) -#define pr_info(arg...) print_trace(__FILE__, __LINE__, 2, 1, arg) +#define pr_err(arg...) print_trace(__FILE__, __LINE__, 1, TRACE_ERR, arg) +#define pr_warn(arg...) print_trace(__FILE__, __LINE__, 2, TRACE_WARN, arg) +#define pr_info(arg...) print_trace(__FILE__, __LINE__, 2, TRACE_INFO, arg) +#define pr_debug(arg...) print_trace(__FILE__, __LINE__, 2, TRACE_DEBUG, arg) int open_log_file(const char *logfile); -- 2.45.0