From 0b301a7ed041c85548b896418d926563e6eb0762 Mon Sep 17 00:00:00 2001 From: Danny Holman Date: Wed, 18 Sep 2024 01:08:04 -0500 Subject: core: logging: print errors and warnings in color Print warnings and errors in yellow and red respectively. This will make these messages stand out and make it easier for a developer to find them in the terminal window. Signed-off-by: Danny Holman --- core/logging.c | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) (limited to 'core') diff --git a/core/logging.c b/core/logging.c index 98ee55b..df97b4d 100644 --- a/core/logging.c +++ b/core/logging.c @@ -3,11 +3,13 @@ #include #include -#define LSTR_FATAL "[FATAL]" -#define LSTR_ERROR "[ERROR]" -#define LSTR_WARN "[WARNING]" -#define LSTR_INFO "[INFO]" -#define LSTR_DEBUG "[DEBUG]" +#define LSTR_FATAL "\033[31m[FATAL]" +#define LSTR_ERROR "\033[31m[ERROR]" +#define LSTR_WARN "\033[33m[WARNING]" +#define LSTR_INFO "\033[0m[INFO]" +#define LSTR_DEBUG "\033[32m[DEBUG]" + +static int debug_enabled = 0; void log_output(int level, const char *fmt, ...) { char out[8192]; @@ -33,8 +35,18 @@ void log_output(int level, const char *fmt, ...) { lvl_str = LSTR_INFO; break; case LOG_DEBUG: + if (debug_enabled == 0) + return; lvl_str = LSTR_DEBUG; break; } - printf("%s %s\n", lvl_str, out); + printf("%s %s\n%s", lvl_str, out, "\033[0m"); +} + +void enable_log_debug(void) { + debug_enabled = 1; +} + +void disable_log_debug(void) { + debug_enabled = 0; } -- cgit v1.2.3