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: LogFilterPatterns= drops a service's noisy lines before journalctl stores them

Journalctl
~/tips/tip-systemd-logfilterpatterns

sudo systemctl edit myapp.service

Stop a service's repetitive log lines from being stored in the journal at all.

Some services log the same pointless line every few seconds, like a health check that passed again. You can filter it out when you read the log, but it still takes up journal space. Since systemd 253 a service can drop those lines before they’re stored.

sudo systemctl edit myapp.service

Add this in the editor, then restart the service:

[Service]
LogFilterPatterns=~health check OK
LogFilterPatterns=~GET /ping

Each pattern is an extended regular expression that’s matched against the message text. The ~ in front makes it a deny pattern, so matching lines are thrown away. Without the ~ it’s an allow pattern, and as soon as you have one of those, only lines that match an allow pattern are kept. Deny patterns are checked first. A message that really starts with a tilde needs \x7e instead.

After the restart, journalctl -u myapp no longer shows the noise, and the filtered lines aren’t forwarded to syslog, the console or wall messages either.

Some caveats. The lines are gone for good, not hidden, so a pattern that’s too broad can cost you the one line you needed later. My advice is to keep patterns as specific as you can. It only works for system services, not for --user units. The messages systemd writes about the unit itself (started, stopped, failed) are never filtered. And on a systemd older than 253, check with systemctl --version, the setting doesn’t exist yet.

Further reading: systemd.exec(5) man page: LogFilterPatterns=

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