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: SyslogIdentifier= gives a systemd service a readable name in the log

Systemd
~/tips/tip-systemd-syslog-identifier

[Service]

Replace names like sh, python3 or java in log lines with the name of your service.

A service that starts through sh -c or a Python interpreter shows up in the log as sh[1234] or python3[1234]. With three such services on a box, that tells you nothing.

Set the name yourself:

[Service]
ExecStart=/usr/bin/python3 /opt/myapp/app.py
SyslogIdentifier=myapp

Every line the service prints to stdout or stderr now carries myapp as its tag. For a unit that starts /bin/sh -c "echo out-line", the line changes from the program name to demoapp[160]: out-line once SyslogIdentifier=demoapp is set.

The tag lands in the SYSLOG_IDENTIFIER field, so you can also filter on it:

journalctl -t myapp --since today

I find that useful when a template has several instances: give each one its own tag with SyslogIdentifier=myapp-%i.

It only applies to output that goes through systemd’s stdout and stderr handling. If the program logs to the journal itself, or to /dev/log through a syslog library, it sets its own identifier and this setting does not change it.

Further reading: systemd.exec man page

More Systemd tips [Service] sudo mkdir -p /etc/systemd/system/service.d [Service] printf 'hunter2' | sudo systemd-creds encrypt --name=dbpass – dbpass.cred systemd-analyze timespan 1h30min All Systemd tips (88) All topics

Link