0

I have a service, for example :

[Unit]
Description=My app
PartOf=myorg.target
After=network-online.target

[Service]
Type=notify
User=myuser
NotifyAccess=main
ExecStart=/usr/bin/my_app
Restart=always
RestartSec=1s

[Install]
WantedBy=myorg.target
Alias=myapp.service

Its logs are visible in journalctl. One log example :

Feb 16 08:32:11 mycomputer-0013952a677a hapic[410613]: TheLogMessage

Format look like :

<date> <hostname> <logger name>[<thread id>]: <message>

How can I configure this format ? My goal is to add the service alias in log format.

bux
  • 626
  • 2
  • 6
  • 20
  • That really depends on how the log messages get written in the first place... A fairly common is that you service generates standard output and systemd subsequently streams that output to journald, with each new line marking a new entry. I think you should be able to set extra meta data in the journal message with the setting [`LogExtraFields=`](https://www.freedesktop.org/software/systemd/man/systemd.exec.html#LogExtraFields=) and https://www.freedesktop.org/software/systemd/man/systemd.journal-fields.html – Bob Feb 16 '22 at 14:20
  • Thanks for your reply. For information, I found another solution : Add en var containing my service name with "Environment" parameter and use its value in my program to prefix my log messages. – bux Feb 23 '22 at 09:28
  • See https://serverfault.com/questions/695505/change-systemd-unit-tag-send-to-journalctl-syslog – reinierpost Nov 11 '22 at 16:37

0 Answers0