aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoão Valverde <j@v6e.pt>2021-12-14 01:22:24 +0000
committerWireshark GitLab Utility <gerald+gitlab-utility@wireshark.org>2021-12-14 12:05:41 +0000
commitcf3cb3a695c1df24c8bf7047a63779b6e407a6a7 (patch)
treefe4e87005ca561c323535b846058456655085f69
parent77b6bca3870d5ef63303e637cc39e2cf83f49ddc (diff)
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.
-rw-r--r--debian/libwsutil0.symbols2
-rw-r--r--extcap/extcap-base.c2
-rw-r--r--ui/qt/main.cpp2
-rw-r--r--wsutil/wslog.c13
-rw-r--r--wsutil/wslog.h10
5 files changed, 17 insertions, 12 deletions
diff --git a/debian/libwsutil0.symbols b/debian/libwsutil0.symbols
index 3b78598c57..951712dcce 100644
--- a/debian/libwsutil0.symbols
+++ b/debian/libwsutil0.symbols
@@ -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
diff --git a/extcap/extcap-base.c b/extcap/extcap-base.c
index c4111405c2..c44981eed2 100644
--- a/extcap/extcap-base.c
+++ b/extcap/extcap-base.c
@@ -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)
diff --git a/ui/qt/main.cpp b/ui/qt/main.cpp
index edfb715914..f145f839a6 100644
--- a/ui/qt/main.cpp
+++ b/ui/qt/main.cpp
@@ -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);
diff --git a/wsutil/wslog.c b/wsutil/wslog.c
index 47d6227d7d..9f53ce519c 100644
--- a/wsutil/wslog.c
+++ b/wsutil/wslog.c
@@ -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;
}
diff --git a/wsutil/wslog.h b/wsutil/wslog.h
index 437f12e163..943f2b017a 100644
--- a/wsutil/wslog.h
+++ b/wsutil/wslog.h
@@ -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. */