wslog: Remove (part of) a special case for the default level

Instead of removing extra log information in the log handler
for the default log level, do it in the ws_message() macro.

This means ws_log_full() will work as expected.
This commit is contained in:
João Valverde 2021-11-14 15:51:51 +00:00
parent b30a2112e8
commit c92e4ff7c6
2 changed files with 14 additions and 9 deletions

View File

@ -738,8 +738,6 @@ static void log_write_do_work(FILE *fp, gboolean use_color,
const char *file, int line, const char *func,
const char *user_format, va_list user_ap)
{
gboolean doextra = (level != DEFAULT_LOG_LEVEL);
#ifndef WS_DISABLE_DEBUG
if (!init_complete)
fputs(" ** (noinit)", fp);
@ -766,15 +764,15 @@ static void log_write_do_work(FILE *fp, gboolean use_color,
color_off(use_color));
/* File/line */
if (doextra && file != NULL && line >= 0)
if (file != NULL && line >= 0)
fprintf(fp, "%s:%d ", file, line);
else if (doextra && file != NULL)
else if (file != NULL)
fprintf(fp, "%s ", file);
fputs("-- ", fp);
/* Function name */
if (doextra && func != NULL)
if (func != NULL)
fprintf(fp, "%s(): ", func);
/* User message */

View File

@ -234,8 +234,14 @@ void ws_logv_full(const char *domain, enum ws_log_level level,
const char *format, va_list ap);
#define _LOG_FULL(level, ...) ws_log_full(_LOG_DOMAIN, level, \
__FILE__, __LINE__, G_STRFUNC, __VA_ARGS__)
#define _LOG_FULL(level, ...) \
ws_log_full(_LOG_DOMAIN, level, \
__FILE__, __LINE__, __func__, __VA_ARGS__)
#define _LOG_SIMPLE(level, ...) \
ws_log_full(_LOG_DOMAIN, level, \
NULL, -1, NULL, __VA_ARGS__)
/** Logs with "error" level.
*
@ -259,9 +265,10 @@ void ws_logv_full(const char *domain, enum ws_log_level level,
/** Logs with "message" level.
*
* Accepts a format string and includes the file and function name.
* Accepts a format string and *does not* include the file and function
* name. This is the default log level.
*/
#define ws_message(...) _LOG_FULL(LOG_LEVEL_MESSAGE, __VA_ARGS__)
#define ws_message(...) _LOG_SIMPLE(LOG_LEVEL_MESSAGE, __VA_ARGS__)
/** Logs with "info" level.
*