Score:0

How to configure service log format?

mx flag
bux

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.

ru flag
See https://serverfault.com/questions/695505/change-systemd-unit-tag-send-to-journalctl-syslog
cn flag
Bob
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
mx flag
bux
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.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.