[systemd-devel] journald not associating log messages with service
Lennart Poettering
lennart at poettering.net
Tue Jul 28 14:44:12 UTC 2020
On Sa, 25.07.20 17:22, Ian Pilcher (arequipeno at gmail.com) wrote:
> I have a simple (non-forking) one-shot service that logs messages via
> syslog. These messages are not being "associated" with the service
> unit. I.e., they don't show up if I use journalctl's -u option
> (although they are in the journal).
>
> UPDATE: I just tried using sd_journal_print, and I'm seeing exactly the
> same behavior.
>
> This is a templated service, if that matters.
>
> Any idea what I can do to get these messages properly associated?
Is the service short-lived? There's a race: if a process runs very
quickly and logs journald might process the message after the process
already exited, i.e. at a time where we can't read the cgroup off the
process anymore.
Sucks, and it would be great if the kernel could just send the cgroup
info along...
You can artifically delay your service's exit (sleep 10...) but it's
still racy and sucks hard. You could issue the equivalent of
"journalctl --sync" at the end of your program...
Lennart
--
Lennart Poettering, Berlin
More information about the systemd-devel
mailing list