[systemd-devel] Detecting when running under systemd

Peter Hoeg peter at hoeg.com
Wed Aug 17 08:44:19 UTC 2022


> you want to check specifically whether stderr is tied to the journal, for which you can use JOURNAL_STREAM

You are right, nice catch!

> (In addition to disabling the timestamps you should *at least* add message priority indicators as well, either by using SyslogLevelPrefix=, or by avoiding stderr entirely and using the syslog() API for logging – if not going all the way with sd_journal_send*().)

It's an application written in crystal, so while it would be straight forward to either use the syslog API or write bindings for sd_journal_send, my logging requirements are basic (to put it mildly) and simply dumping to stderr works well enough when paired with the priority parsing provided by SyslogLevelPrefix.

Thank you!


More information about the systemd-devel mailing list