systemd:如何设置 stdout/stderr 上消息的默认日志级别?

dus*_*msk 5 linux logging systemd

我正在将应用程序作为 systemd 服务运行。应用程序按照 systemd 日志记录规则将其输出记录到 stdout - 在每条日志消息前面添加 <x>,其中 x 是优先级(日志级别)。

<6> this is info
<7> this is debug
<4> this is warning
Run Code Online (Sandbox Code Playgroud)

我想要的是仅将优先级 <= 6 存储到日志中,因为我在闪存盘上运行。我不想存储调试消息以及未用 <> 标记的消息/“垃圾”。

似乎不是问题 - MaxLevelStore=info。

但是 - 问题是写入 stdout 的“垃圾”默认标记为priority=6(信息),并且也存储在日志数据库内。我想要的是默认将其标记为调试(7),因此从以下输出:

<6> this is info
<7> this is debug
this is some trash
<4> this is warning
Run Code Online (Sandbox Code Playgroud)

...只会...

<6> this is info
<4> this is warning
Run Code Online (Sandbox Code Playgroud)

...存储到日志中。

在我拥有的所有文档中找不到这是否/如何可能。有人吗?

谢谢

小智 6

SyslogLevel=debug您想在[Service]您的服务部分使用。这将导致所有没有以优先级为前缀的消息默认具有调试级别 (7)。

文档: https://www.freedesktop.org/software/systemd/man/systemd.exec.html#SyslogLevel=