Some error messages in journalctl
show up in red and white. If I'm authoring my own systemd
service, how can I format my messages such that they show up in red or white. It's a nice way of having errors stand out.
1 Answer
It's the priority that determines how journalctl displays messages.
Based on a quick test with logger
:
- Messages of priority
debug
andinfo
are displayed "normally". - Messages of priority
notice
andwarning
are displayed in bold white. - Messages of priority
err
,crit
,alert
,emerg
are displayed in bold red.
Edit:
To answer the comment about how to indicate a level just by writing to stdout, yes you can, just prefix your message with <n>
where n is a number between 0 (emerg) and 7 (debug) representing the priority.
For example the following service writes an alert
message, which will thus appear in red in journalctl output :
[Unit]
Description=Loth
[Service]
ExecStart=/bin/echo "<1>Victoriae mundis et mundis lacrima."
[Install]
WantedBy=multi-user.target
See sd-daemon(3)
and http://0pointer.de/blog/projects/journal-submit.html for more details.
-
1If your service is just writing to stdout, is there a way to indicate loglevel?– Chris W.Jun 9, 2016 at 16:47