GNOME Bugzilla – Bug 792432
flush stdout after logging (debug) messages
Last modified: 2018-01-15 18:47:22 UTC
The default log handler does not flush the output after logging messages. Unfortunately, the default for stdout buffering is fully buffered when it is not a TTY. This means that reading g_debug messages from spawned processes during testing is impossible without further preparations, as the debug messages are still hanging in the output buffer. This is used e.g. gnome-settings-daemon power plugin for testing the gsd-power process. The easy fix would be to just add an explicit fflush in g_log_writer_standard_streams.
(In reply to Benjamin Berg from comment #0) > The default log handler does not flush the output after logging messages. > Unfortunately, the default for stdout buffering is fully buffered when it is > not a TTY. This means that reading g_debug messages from spawned processes > during testing is impossible without further preparations, as the debug > messages are still hanging in the output buffer. > > This is used e.g. gnome-settings-daemon power plugin for testing the > gsd-power process. > > The easy fix would be to just add an explicit fflush in > g_log_writer_standard_streams. Sure, given that the unit of flushing is an entire log message, rather than a few bytes, this probably won’t hurt performance. Patch welcome.
Created attachment 366846 [details] [review] gmessages: Flush output stream after logging messages When debug output is enabled then certain messages will be logged to stdout. stdout however is block buffered by default when it isn't going to a TTY meaning that debug logging will not be flushed out properly when it is being redirected. One example of this happening may be tests that rely on parsing g_debug messages. Adding an explicit fflush ensures all log messages will reach the output.
Review of attachment 366846 [details] [review]: ++, thanks.
Thanks! Attachment 366846 [details] pushed as 5fba62a - gmessages: Flush output stream after logging messages