3

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.

6

It's the priority that determines how journalctl displays messages.

Based on a quick test with logger :

  • Messages of priority debug and info are displayed "normally".
  • Messages of priority notice and warning 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.

  • If your service is just writing to stdout, is there a way to indicate loglevel? – Chris W. Jun 9 '16 at 16:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.