aboutsummaryrefslogtreecommitdiffstats
path: root/wsutil/wslog.c
diff options
context:
space:
mode:
authorJoão Valverde <joao.valverde@tecnico.ulisboa.pt>2021-06-19 01:41:22 +0100
committerJoão Valverde <joao.valverde@tecnico.ulisboa.pt>2021-06-19 02:07:34 +0100
commitdddb33e398d80d3f4bfc263ec3d2fa7286634493 (patch)
treecdae1dd5e4ce1af261c3a06e33b93c2edf4bc4f8 /wsutil/wslog.c
parent39315979c638b916d76a9dbf8c7ffb089721f01a (diff)
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.
Diffstat (limited to 'wsutil/wslog.c')
-rw-r--r--wsutil/wslog.c15
1 files 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) {