After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 792432 - flush stdout after logging (debug) messages
flush stdout after logging (debug) messages
Status: RESOLVED FIXED
Product: glib
Classification: Platform
Component: general
unspecified
Other Linux
: Normal normal
: ---
Assigned To: gtkdev
gtkdev
Depends on:
Blocks:
 
 
Reported: 2018-01-11 14:37 UTC by Benjamin Berg
Modified: 2018-01-15 18:47 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
gmessages: Flush output stream after logging messages (1.18 KB, patch)
2018-01-15 16:39 UTC, Benjamin Berg
committed Details | Review

Description Benjamin Berg 2018-01-11 14:37:28 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.
Comment 1 Philip Withnall 2018-01-15 11:12:48 UTC
(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.
Comment 2 Benjamin Berg 2018-01-15 16:39:37 UTC
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.
Comment 3 Philip Withnall 2018-01-15 18:18:30 UTC
Review of attachment 366846 [details] [review]:

++, thanks.
Comment 4 Benjamin Berg 2018-01-15 18:47:18 UTC
Thanks!

Attachment 366846 [details] pushed as 5fba62a - gmessages: Flush output stream after logging messages