wslog: Avoid logging any output to stdout

For historical reasons our logging inherited from GLib the logging of
some levels to stdout. Namely levels "info" and "debug" (to which we
added "noisy").

However this practice is discouraged because it mixes debug output
with application output for CLI tools and breaks many common usage
scenarios, like using tshark in pipes.

This change flips the logic on wslog to make logging to stderr the
default behavior.

Extcap subprocess have a hidden dependency on stdout so add that.

Some GUI users may also have a dependency on stdout. Because
GUI tools are unlikely to depend on stdout for programatic output
add another exception for wireshark GUI, to preserve backward
compatibility.
This commit is contained in:
João Valverde 2021-12-14 01:22:24 +00:00 committed by Wireshark GitLab Utility
parent 77b6bca387
commit cf3cb3a695
5 changed files with 17 additions and 12 deletions

View File

@ -382,7 +382,7 @@ libwsutil.so.0 libwsutil0 #MINVER#
ws_log_add_custom_file@Base 3.5.0
ws_log_buffer_full@Base 3.5.1
ws_log_console_writer@Base 3.7.0
ws_log_console_writer_set_use_stderr@Base 3.7.0
ws_log_console_writer_set_use_stdout@Base 3.7.0
ws_log_file_writer@Base 3.7.0
ws_log_full@Base 3.5.0
ws_log_get_level@Base 3.5.0

View File

@ -112,6 +112,8 @@ void extcap_base_set_running_with(extcap_parameters * extcap, const char *fmt, .
void extcap_log_init(const char *progname)
{
ws_log_init(progname, NULL);
/* extcaps cannot write debug information to parent on stderr. */
ws_log_console_writer_set_use_stdout(TRUE);
}
uint8_t extcap_base_parse_options(extcap_parameters * extcap, int result, char * optargument)

View File

@ -520,6 +520,8 @@ int main(int argc, char *qt_argv[])
/* Initialize log handler early so we can have proper logging during startup. */
ws_log_init_with_writer("wireshark", console_log_writer, vcmdarg_err);
/* For backward compatibility with GLib logging and Wireshark 3.4. */
ws_log_console_writer_set_use_stdout(TRUE);
qInstallMessageHandler(qt_log_message_handler);

View File

@ -84,8 +84,9 @@ static gboolean stdout_color_enabled = FALSE;
static gboolean stderr_color_enabled = FALSE;
/* Use stderr for levels "info" and below. */
static gboolean stderr_debug_enabled = FALSE;
/* Use stdout for levels "info" and below, for backward compatibility
* with GLib. */
static gboolean stdout_logging_enabled = FALSE;
static const char *registered_progname = DEFAULT_PROGNAME;
@ -929,7 +930,7 @@ static inline struct tm *get_localtime(time_t unix_time, struct tm **cookie)
static inline FILE *console_file(enum ws_log_level level)
{
if (level <= LOG_LEVEL_INFO && !stderr_debug_enabled)
if (level <= LOG_LEVEL_INFO && stdout_logging_enabled)
return stdout;
return stderr;
}
@ -937,7 +938,7 @@ static inline FILE *console_file(enum ws_log_level level)
static inline bool console_color_enabled(enum ws_log_level level)
{
if (level <= LOG_LEVEL_INFO && !stderr_debug_enabled)
if (level <= LOG_LEVEL_INFO && stdout_logging_enabled)
return stdout_color_enabled;
return stderr_color_enabled;
}
@ -1098,9 +1099,9 @@ void ws_log_console_writer(const char *domain, enum ws_log_level level,
WS_DLL_PUBLIC
void ws_log_console_writer_set_use_stderr(bool use_stderr)
void ws_log_console_writer_set_use_stdout(bool use_stdout)
{
stderr_debug_enabled = use_stderr;
stdout_logging_enabled = use_stdout;
}

View File

@ -68,14 +68,14 @@ void ws_log_console_writer(const char *domain, enum ws_log_level level,
const char *user_format, va_list user_ap);
/** Configure all log output to use stderr.
/** Configure log levels "info" and below to use stdout.
*
* Normally log levels "info", "debug" and "noisy" are written to stdout.
* Calling this function with true configures these levels to be written
* to stderr as well.
* Normally all log messages are written to stderr. For backward compatibility
* with GLib calling this function with TRUE configures log levels "info",
* "debug" and "noisy" to be written to stdout.
*/
WS_DLL_PUBLIC
void ws_log_console_writer_set_use_stderr(bool use_stderr);
void ws_log_console_writer_set_use_stdout(bool use_stdout);
/** Convert a numerical level to its string representation. */