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?
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.Sign up to join this community
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
$ 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"