mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-07-29 21:33:30 +02:00
gmessages: Add API to move info and debug messages to stderr
GLib code normally prints info and debug messages to stdout, but that interferes with programs that are documented to produce machine-readable output such as JSON or XML on stdout. In particular, if such a program uses a GLib-based library, setting G_MESSAGES_DEBUG will typically result in that library's debug messages going to the program's stdout and corrupting the machine-readable output. Unix programs can avoid this by using dup2() to move the original stdout to another fd, then dup2() again to make the new stdout a copy of stderr, but it's easier if we provide a way to not write debug messages to stdout in the first place. Calling g_log_writer_default_set_use_stderr (TRUE) results in behaviour resembling Python's logging.basicConfig(), with all diagnostics going to stderr. Suggested by Allison Karlitskaya on glib#2087. Signed-off-by: Simon McVittie <smcv@collabora.com>
This commit is contained in:
committed by
Philip Withnall
parent
97956c2d3d
commit
10b0ece9d8
@@ -1484,6 +1484,7 @@ g_log_writer_format_fields
|
||||
g_log_writer_journald
|
||||
g_log_writer_standard_streams
|
||||
g_log_writer_default
|
||||
g_log_writer_default_set_use_stderr
|
||||
|
||||
<SUBSECTION Private>
|
||||
g_log_structured_standard
|
||||
|
Reference in New Issue
Block a user