[systemd-devel] Prefix for direct logging

Mantas Mikulėnas grawity at gmail.com
Tue Sep 28 06:01:56 UTC 2021


On Tue, Sep 28, 2021, 06:07 Arjun D R <drarjun95 at gmail.com> wrote:

> Thank you Mantas for the details.
> How do you currently get the logs "every few seconds"?
> > Actually we have a script that will be triggered every 10 seconds. That
> script will run "journalctl -u <service>" and redirect the output to the
> respective log file. We will run journalctl for around 40-50 services for
> every 10 seconds and redirect it to the respective log files. That may be a
> bad idea, but this is how we are collecting logs as of now. We need to
> separate the logs for every service and that's why we ended up with this
> implementation.
>

So replace it with 40-50 instances of continuously running `[stdbuf -o0]
journalctl -f -u <service>`.

Although syslogd might be easier, since then you'd only need one process
doing the monitoring. (I know both syslogds can access journal fields like
_SYSTEMD_UNIT, but I don't know how, so usually I just filter by the
traditional "program name" and it does the job.)

You could also have a custom daemon that reads from `journalctl -f -o json`
and writes to the appropriate text log...


>
> Ah, ok so StandardOutput:file:<log_file> will allow the service to open
> the fd and directly connect it to the service stdout.
>

Yes, so if you want timestamps they have to be provided by your service,
pretty much like how most services implement direct logging to files.
(Probably the only advantage of StandardOutput is that the service doesn't
need permissions to /var/log...)

>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/systemd-devel/attachments/20210928/0b11cecc/attachment-0001.htm>


More information about the systemd-devel mailing list