How to Customize Systemd Service Log Identifiers in Journalctl for Better Log Management


2 views

When working with systemd services, you might notice that journalctl doesn't always use the service name as the log identifier. For example, with a PHP-based service called report-daemon.service, logs appear as coming from php rather than your service name. This happens because systemd defaults to using the executable name from ExecStart for logging.

Proper log tagging is crucial for:

  • Effective log filtering (journalctl -u service-name)
  • Centralized log management systems
  • Service-specific log analysis
  • Debugging multi-service systems

Systemd provides the SyslogIdentifier directive specifically for this purpose. Add it to your service's [Service] section:

[Unit]
Description=Report Generation Daemon

[Service]
ExecStart=/usr/bin/php /path/to/script.php
SyslogIdentifier=report-daemon
Restart=always
User=www-data

[Install]
WantedBy=multi-user.target

After reloading systemd and restarting your service:

systemctl daemon-reload
systemctl restart report-daemon.service
journalctl -u report-daemon -n 5

Now your logs should show the correct identifier:

May 30 16:26:11 delta report-daemon[994]: Found 0 new revisions for Ctytn4a6zjw

For more complex scenarios, consider these additional parameters:

[Service]
SyslogIdentifier=report-daemon
SyslogFacility=local0
SyslogLevel=info
LogLevelMax=warning

If you need more control over logging format, consider using a wrapper script:

#!/bin/bash
exec /usr/bin/php /path/to/script.php 2>&1 | logger -t report-daemon

Then update your service file:

[Service]
ExecStart=/path/to/wrapper.sh
Type=simple
  • Verify journald configuration: journalctl --verify
  • Check for conflicting settings in /etc/systemd/journald.conf
  • Ensure proper permissions for logging
  • Use journalctl --identifier=report-daemon for precise filtering

For centralized logging systems like ELK or Graylog, consistent tagging becomes even more important. The SyslogIdentifier ensures your service logs maintain proper context when aggregated with other system logs.


When working with systemd-managed services, you might notice that journalctl displays process identifiers that don't always match your service name. This happens because systemd defaults to using the executable name from ExecStart as the logging identifier.

May 30 16:26:11 delta php[994]: Found 0 new revisions for Ctytn4a6zjw

Instead of showing report-daemon as you'd expect, it shows php because that's the interpreter running your service.

Systemd provides the SyslogIdentifier option in service unit files to override this behavior:

[Service]
ExecStart=/usr/bin/php /path/to/script.php
SyslogIdentifier=report-daemon

After adding this directive and reloading the service (systemctl daemon-reload), your logs will display the correct identifier:

May 30 16:26:11 delta report-daemon[994]: Found 0 new revisions for Ctytn4a6zjw

For more control over logging behavior, consider these additional directives:

[Service]
SyslogIdentifier=custom-service
SyslogFacility=local0
SyslogLevel=info
LogLevelMax=warning

After making changes, verify your configuration with:

journalctl --unit=report-daemon -o verbose

Look for the SYSLOG_IDENTIFIER field in the output to confirm your changes took effect.

Some scenarios require special handling:

  • For shell scripts or interpreters, set the identifier explicitly
  • When using User= directive, ensure proper permissions
  • With multiple ExecStart commands, the first one usually determines the default identifier