From dddb33e398d80d3f4bfc263ec3d2fa7286634493 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Valverde?= Date: Sat, 19 Jun 2021 01:41:22 +0100 Subject: [PATCH] wslog: Be more obvious in the log that the domain is unset Currently we are not filtering the unset (NULL) domain, on the assumption that every log call should belong to a defined domain. However there are still many places in the codebase where this isn't true and the fact that the null/default domain name is omitted from the output and never filtered is probably surprising and user-unfriendly. Users might understandably assume the filtering is buggy. Give an indication, such as (none)-MESSAGE, to make this more obvious. --- wsutil/wslog.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/wsutil/wslog.c b/wsutil/wslog.c index 94e9b3fd4a..089ecbe46c 100644 --- a/wsutil/wslog.c +++ b/wsutil/wslog.c @@ -94,7 +94,7 @@ const char *ws_log_level_to_string(enum ws_log_level level) { switch (level) { case LOG_LEVEL_NONE: - return "(none)"; + return "(zero)"; case LOG_LEVEL_ERROR: return "ERROR"; case LOG_LEVEL_CRITICAL: @@ -139,6 +139,13 @@ static enum ws_log_level string_to_log_level(const char *str_level) } +WS_RETNONNULL +static inline const char *domain_to_string(const char *domain) +{ + return (domain == NULL) ? "(none)" : domain; +} + + static inline gboolean log_level_is_active(enum ws_log_level level) { /* @@ -536,6 +543,7 @@ static void log_write_do_work(FILE *fp, gboolean use_color, const char *timestam const char *file, int line, const char *func, const char *user_format, va_list user_ap) { + const char *domain_str = domain_to_string(domain); const char *level_str = ws_log_level_to_string(level); gboolean doextra = (level != LOG_LEVEL_MESSAGE); @@ -552,10 +560,7 @@ static void log_write_do_work(FILE *fp, gboolean use_color, const char *timestam fputc(' ', fp); } - if (DOMAIN_NOTSET(domain)) - fprintf(fp, "[%s] ", level_str); - else - fprintf(fp, "[%s-%s] ", domain, level_str); + fprintf(fp, "[%s-%s] ", domain_str, level_str); if (doextra) { if (file && line >= 0) {