11

I have a script that I intend to run as a systemd service.

I know that stdout and stderr will be routed to the systemd journal. Is there any way for me to indicate that a line of output be treated as INFO or ERROR or whatever is appropriate?

0

1 Answer 1

15

From systemd for Developers III: Revenge of the systemd we find:

The printed string in this example is logged at a default log priority of LOG_INFO1. Sometimes it is useful to change the log priority for such a printed string. When systemd parses STDOUT/STDERR of a service it will look for priority values enclosed in < > at the beginning of each line

And the magic numbers are apparently copied from syslog(3) so

$ egrep 'INFO|ERR' /usr/include/sys/syslog.h | fgrep define
#define LOG_ERR     3   /* error conditions */
#define LOG_INFO    6   /* informational */
#define LOG_PERROR  0x20    /* log to stderr as well */

To emit info or error messages from e.g. a TCL script would look something like

#!/usr/bin/env expect
puts "<3>auuugh"
puts "<6>infos"
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .