如何指示 systemd 服务输出行的日志级别?

Dan*_*umb 6 systemd systemd-journald

我有一个脚本,打算作为 systemd 服务运行。

我知道 stdout 和 stderr 将被路由到 systemd 日志。有什么方法可以让我表明一行输出被视为 INFO 或 ERROR 或任何合适的?

thr*_*rig 12

systemd for Developers III: Revenge of the systemd我们发现:

此示例中的打印字符串以 LOG_INFO 1的默认日志优先级记录。有时更改此类打印字符串的日志优先级很有用。当 systemd 解析服务的 STDOUT/STDERR 时,它会在每一行的开头查找 < > 中包含的优先级值

神奇的数字显然是从syslog(3)这样复制的

$ 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 */
Run Code Online (Sandbox Code Playgroud)

从例如 TCL 脚本发出信息或错误消息看起来像

#!/usr/bin/env expect
puts "<3>auuugh"
puts "<6>infos"
Run Code Online (Sandbox Code Playgroud)