brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: journalctl _SYSTEMD_UNIT= skips what systemd said about the service

Journalctl
~/tips/tip-journalctl-systemd-unit-field

journalctl _SYSTEMD_UNIT=nginx.service

Show only lines a service wrote itself, without the start and stop messages from systemd.

journalctl -u nginx shows more than nginx’s own lines. It also includes what systemd logged about the unit, like starting, stopping and failing.

Usually that is what you want. When you only want the program’s own output, I’d match the trusted field directly:

journalctl _SYSTEMD_UNIT=nginx.service

The difference is easy to see on a small unit. -u demo.service prints Starting demo.service and Started demo.service from systemd[1], plus the two lines the program printed. _SYSTEMD_UNIT=demo.service prints just those two program lines.

The reason is that -u is a shortcut for several matches combined: the process’s own unit, plus messages from PID 1 and other system services that are about that unit. The raw field only covers processes that ran inside the unit’s cgroup.

The reverse also works if you want only systemd’s view of a unit:

journalctl _PID=1 UNIT=nginx.service

The field match is exact. It takes no glob patterns and no missing .service suffix, so _SYSTEMD_UNIT=nginx finds nothing at all. Use journalctl -F _SYSTEMD_UNIT to copy the right name.

Further reading: journalctl man page, systemd.journal-fields man page

More Journalctl tips journalctl -k -g 'killed process' --since "2 days ago" journalctl _PID=1 -b ls -lh /var/log/journal/*/*.journal~ Storage=volatile sudo journalctl --setup-keys All Journalctl tips (81) All topics

Link