g_log_writer_is_journald memoizes a single result, even though it accepts a parameter
The documentation for g_log_writer_is_journald
says:
Check whether the given @output_fd file descriptor is a connection to the systemd journal, or something else (like a log file or
stdout
orstderr
).
But that's not what the implementation does, since it uses GOnce
to memoize the result of the first call (with whatever FD was passed to it). As a result, if you run the following contrived program:
#!/usr/bin/python3
import sys
import tempfile
from gi.repository import GLib
with tempfile.TemporaryFile() as f:
GLib.log_writer_is_journald(f.fileno())
attrs = ('stdout', 'stderr')
for attr in attrs:
fileno = getattr(sys, attr).fileno()
if GLib.log_writer_is_journald(fileno):
print(attr, 'is journal')
else:
print(attr, 'is not journal')
it will always claim that neither stdout nor stderr is the journal, even when they are:
$ systemd-cat ./foo.py; journalctl --since='1s ago'
-- Logs begin at Mon 2017-10-09 20:47:16 BST, end at Mon 2018-11-12 11:15:36 GMT. --
Nov 12 11:15:36 gelf foo.py[27433]: stdout is not journal
Nov 12 11:15:36 gelf foo.py[27433]: stderr is not journal
Presumably the reason for the GOnce
is so that this check is not performed every time g_log_writer_default
is called; I think it should be floated out into that function.