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.
This commit is contained in:
João Valverde 2021-06-19 01:41:22 +01:00
parent 39315979c6
commit dddb33e398
1 changed files with 10 additions and 5 deletions

View File

@ -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) {