Skip to content

Further logging improvements

Simon McVittie requested to merge wip/smcv/log-flags into main
  • log: Merge g_set_prgname() into _srt_util_set_glib_log_handler()

    If we are going to write to the systemd Journal, we will want the program name to already be known, so that we can use it as the syslog identifier (first argument to sd_journal_stream_fd() and openlog()).

    This also reduces duplication a bit, and brings us one step closer to combining _srt_util_set_up_logging() with _srt_util_set_glib_log_handler().

  • log: Add a custom log level for warnings that won't cause test failure

    In some places, and especially in these logging functions, we can encounter situations that deserve a warning but should not result in program failure, even during unit testing or debugging with G_DEBUG=fatal-warnings. If _srt_log_failure() is like a non-fatal g_error(), then _srt_log_warning() is like a non-fatal g_warning().

  • log: Add file descriptor management in _srt_util_set_glib_log_handler()

    This does a few closely related things.

    If standard input, standard output and standard error are closed, we open them to point to /dev/null, and if they are close-on-exec, we clear their close-on-exec flags. This is to avoid weird side effects: most APIs like open() that create new file descriptors guarantee to use the lowest-numbered fd that is not already in use, but users of those APIs do not expect to be overwriting stdin/stdout/stderr.

    Because that operation can involve changing the meaning of stdout and stderr, we now optionally save a duplicate of the original standard output and standard error, so they can be put back later.

    Because we're now saving a duplicate of the original standard output and standard error, it also makes sense to implement SRT_LOG_FLAGS_DIVERT_STDOUT here. This avoids needing to call _srt_divert_stdout_to_stderr() separately in most callers.

  • glib-backports: Add a backport of g_log_writer_is_journald()

    We can use this the same way GLib does: to detect that stdout or stderr is an inherited Journal stream, so that we can try to do our own Journal logging in preference to using that stream.

  • log: Add Journal integration to GLib log handler

    This has three main functions:

    • If stdout and/or stderr are /dev/null, send warnings to the systemd Journal so they don't get lost, along with debug messages if enabled.

    • If the user requests it, redirect stdout and/or stderr to the systemd Journal so that everything will be logged in one place.

    • If stdout and/or stderr is already a Journal file descriptor inherited from a parent process, reopen it with our own details, and send our log messages with a bit more metadata.

    This obsoletes _srt_util_set_up_logging(), which did the first two of those.

    This is a per-application opt-in, because each application that will make use of this needs to be aware that it might redirect stdout and stderr.

  • tests: Add some coverage for our logging setup

  • pv-adverb: Optionally log to the systemd Journal

    This redirects output produced by pv-adverb, but puts back the original stdout/stderr for the wrapped program (typically the actual game).

  • pv-wrap: Optionally log to systemd Journal

    This redirects output produced by pv-wrap, but puts back the original stdout/stderr for the wrapped program (typically the actual game).

Edited by Simon McVittie

Merge request reports