From c216bb85e75e3db7050f937d6925ba85fb3e6803 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Valverde?= Date: Sat, 19 Jun 2021 05:30:29 +0100 Subject: [PATCH] wslog: Reverse order for level priority Consistently speaking of ascending priority for higher levels seems slightly more intuitive. Use that instead. --- ws_log_defs.h | 16 ++++++++-------- wsutil/wslog.c | 24 ++++++++++++------------ 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/ws_log_defs.h b/ws_log_defs.h index 0bf8c6f647a..214f0ae3971 100644 --- a/ws_log_defs.h +++ b/ws_log_defs.h @@ -37,18 +37,18 @@ #define LOG_DOMAIN_QTUI "GUI" /* - * Descending order by priority needs to be maintained. Higher priorities have - * lower values. + * Ascending order by priority needs to be maintained. Higher priorities have + * higher values. */ enum ws_log_level { LOG_LEVEL_NONE, /* not user facing */ - LOG_LEVEL_ERROR, /* "error" is always fatal (aborts) */ - LOG_LEVEL_CRITICAL, /* always enabled, can be set to fatal */ - LOG_LEVEL_WARNING, /* can be set to fatal */ - LOG_LEVEL_MESSAGE, /* default level, doesn't show file/function name */ - LOG_LEVEL_INFO, /* chatty status but not debug */ - LOG_LEVEL_DEBUG, /* normal debugging level */ LOG_LEVEL_NOISY, /* extra verbose debugging */ + LOG_LEVEL_DEBUG, /* normal debugging level */ + LOG_LEVEL_INFO, /* chatty status but not debug */ + LOG_LEVEL_MESSAGE, /* default level, doesn't show file/function name */ + LOG_LEVEL_WARNING, /* can be set to fatal */ + LOG_LEVEL_CRITICAL, /* always enabled, can be set to fatal */ + LOG_LEVEL_ERROR, /* "error" is always fatal (aborts) */ _LOG_LEVEL_LAST }; diff --git a/wsutil/wslog.c b/wsutil/wslog.c index 0a0eb5a06b5..f4d8505fd3f 100644 --- a/wsutil/wslog.c +++ b/wsutil/wslog.c @@ -58,7 +58,7 @@ typedef struct { char **domainv; gboolean positive; /* positive or negative match */ - enum ws_log_level max_level; /* for level filters */ + enum ws_log_level min_level; /* for level filters */ } log_filter_t; @@ -168,7 +168,7 @@ static gboolean level_filter_matches(log_filter_t *filter, gboolean *active) { ws_assert(filter); - ws_assert(filter->max_level != LOG_LEVEL_NONE); + ws_assert(filter->min_level != LOG_LEVEL_NONE); ws_assert(domain != NULL); ws_assert(level != LOG_LEVEL_NONE); ws_assert(active != NULL); @@ -177,12 +177,12 @@ static gboolean level_filter_matches(log_filter_t *filter, return FALSE; if (filter->positive) { - *active = level >= filter->max_level; + *active = level >= filter->min_level; return TRUE; } /* negative match */ - if (level <= filter->max_level) { + if (level <= filter->min_level) { *active = FALSE; return TRUE; } @@ -194,10 +194,10 @@ static gboolean level_filter_matches(log_filter_t *filter, gboolean ws_log_msg_is_active(const char *domain, enum ws_log_level level) { /* - * Lower numerical levels have higher priority. Critical and above + * Higher numerical levels have higher priority. Critical and above * are always enabled. */ - if (level <= LOG_LEVEL_CRITICAL) + if (level >= LOG_LEVEL_CRITICAL) return TRUE; /* @@ -215,7 +215,7 @@ gboolean ws_log_msg_is_active(const char *domain, enum ws_log_level level) * If the priority is lower than the current minimum drop the * message. */ - if (level > current_log_level) + if (level < current_log_level) return FALSE; /* @@ -414,7 +414,7 @@ static void free_log_filter(log_filter_t **filter_ptr) static void tokenize_filter_str(log_filter_t **filter_ptr, const char *str_filter, - enum ws_log_level max_level) + enum ws_log_level min_level) { char *tok, *str; const char *sep = ",;"; @@ -452,7 +452,7 @@ static void tokenize_filter_str(log_filter_t **filter_ptr, const char *str_filte filter = g_new(log_filter_t, 1); filter->domainv = (void *)g_ptr_array_free(ptr, FALSE); filter->positive = !negated; - filter->max_level = max_level; + filter->min_level = min_level; *filter_ptr = filter; } @@ -482,8 +482,8 @@ enum ws_log_level ws_log_set_fatal(enum ws_log_level log_level) { ws_assert(log_level > LOG_LEVEL_NONE); - /* Not possible to set lower level than "warning" to fatal. */ - if (log_level > LOG_LEVEL_WARNING) + /* Not possible to set lower priority than "warning" to fatal. */ + if (log_level < LOG_LEVEL_WARNING) return LOG_LEVEL_NONE; fatal_log_level = log_level; @@ -635,7 +635,7 @@ static void log_write_dispatch(const char *domain, enum ws_log_level level, g_free(tstamp); ws_assert(level != LOG_LEVEL_NONE); - if (level <= fatal_log_level) { + if (level >= fatal_log_level) { G_BREAKPOINT(); ws_assert_not_reached(); }