Skip to content

logger: Don't line-buffer output to terminal

Simon McVittie requested to merge wip/smcv/logger-buffering into main
  • logger: Don't clear Journal fd twice

    glnx_close_fd() is idempotent, so this was harmless, but it's also useless.

  • logger: If using stderr as a stream to the Journal, don't close it

    We never want to mark stdin/stdout/stderr as close-on-exec, or close them explicitly, but it could be reasonable for self->journal_fd to be STDERR_FILENO.

  • logger: When writing to Journal via stderr, take the Journal code path

    This will matter for things like deciding whether to write out complete vs. partial log lines, and whether to parse and/or send severity prefixes like <4>Something bad happened\n.

    Using STDERR_FILENO for the journal_fd is safe since the previous commit.

  • logger: Copy log messages to terminal/stderr without delay

    If the process that is wrapped by the logger is an interactive CLI such as apt-get, then we want prompts and similar interactive content to get to the terminal as quickly as possible, without waiting for the end of a line to be reached. Separate the processing of partial lines (which we send to the terminal ASAP) from the processing of complete lines (which we still buffer, so that we can send them to the log file or systemd Journal as a complete line, to avoid log rotation happening halfway through a line).

    We have a fallback code path that logs to standard error, which is used if all other log destinations (log file, terminal, Journal) are disabled. We don't know the file type of standard error (it could be an interactive terminal, a pipe or socket, or something else) so err on the side of sending partial messages on that code path without delay as well.

    steamrt/tasks#447

  • tests: Test that messages to a (mock) terminal are not buffered

  • tests: Add missing coverage for srt-logger --journal-fd


Prompted by work on steamrt/tasks#447.

/cc @refi64

Merge request reports