From a4308d5f133e67c2292578277c7a8cb3af790fd5 Mon Sep 17 00:00:00 2001 From: Alessandro Iezzi Date: Mon, 27 Feb 2023 16:41:14 +0100 Subject: Add NONE level It's used to disable logs for a specific tag. --- src/log.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/log.c b/src/log.c index a7605da..b8d0be9 100644 --- a/src/log.c +++ b/src/log.c @@ -7,10 +7,11 @@ #include "log.h" -#define DBG_LVL 0 -#define INF_LVL 1 -#define WRN_LVL 2 -#define ERR_LVL 3 +#define NNN_LVL -1 /* NONE LEVEL */ +#define DBG_LVL 0 +#define INF_LVL 1 +#define WRN_LVL 2 +#define ERR_LVL 3 #define BUFF_SIZE 256 #define HALF_SIZE (BUFF_SIZE / 2 - 1) @@ -54,6 +55,7 @@ check_term_colors() static int log_parse_level_property(char *str_level) { + if (strcmp( str_level, "NONE" ) == 0) return NNN_LVL; if (strcmp( str_level, "DEBUG" ) == 0) return DBG_LVL; if (strcmp( str_level, "INFO" ) == 0) return INF_LVL; if (strcmp( str_level, "WARNING" ) == 0) return WRN_LVL; @@ -176,6 +178,9 @@ print_log(Log *log, int level, char *msg) struct tm *date; const char *lvl; + /* NONE level. Disable log */ + if (log->level == NNN_LVL) return; + /* Don't display log if the choosen level is major. * For example: log->level is ERROR and level is INFO, only ERROR logs will be shown. */ if (log->level > level) return; -- cgit v1.2.3