【问题标题】:Redirect docker log messages into different syslog file (froward by logspout)将 docker 日志消息重定向到不同的 syslog 文件(由 logspout 转发)
【发布时间】:2026-02-05 23:25:01
【问题描述】:

我已经设置了一个带有一些 docker 容器的主机,其中 logspout 用于将所有日志记录转发到 syslog:

docker run --name="logspout" -d \
  --restart=unless-stopped \
  --volume=/var/run/docker.sock:/var/run/docker.sock \
  --log-opt tag="logspout" \
  gliderlabs/logspout \
  syslog://host-01.example.com:514

所有日志都在/var/log/syslog中

我现在想将它们拆分为每个容器的文件,因为它变得杂乱无章。

当我将 rsyslog 配置为使用不同的文件时:

munin-server.*                  /var/log/munin.log

我在 syslog 中收到以下消息:

May  9 12:44:39 docker-host-01 rsyslogd: [origin software="rsyslogd" swVersion="8.16.0" x-pid="13893" x-info="http://www.rsyslog.com"] start
May  9 12:44:39 docker-host-01 rsyslogd-2222: command 'KLogPermitNonKernelFacility' is currently not permitted - did you already set it via a RainerScript command (v6+ config)? [v8.16.0 try http://www.rsyslog.com/e/2222 ]
May  9 12:44:39 docker-host-01 rsyslogd-2184: action 'munin-server' treated as ':omusrmsg:munin-server' - please use ':omusrmsg:munin-server' syntax instead, 'munin-server' will not be supported in the future [v8.16.0 try http://www.rsyslog.com/e/2184 ]
May  9 12:44:39 docker-host-01 rsyslogd-3000: user name 'munin-se...' too long - ignored [v8.16.0]
May  9 12:44:39 docker-host-01 rsyslogd-2207: error during parsing file /etc/rsyslog.d/40-default.conf, on or before line 5: warnings occured in file '/etc/rsyslog.d/40-default.conf' around line 5 [v8.16.0 try http://www.rsyslog.com/e/2207 ]

有没有办法以某种方式更改名称(例如 munin-server)?还是该消息具有误导性?

【问题讨论】:

    标签: docker logging rsyslog


    【解决方案1】:

    您使用的旧语法需要 facility.priority 形式的 selector,但设施集是固定的,不包含任意字符串。

    例如,您需要一个旧的property filter 作为选择器。它的形式为 :property, [!]operation, "value" 后跟操作。

    所以你可以尝试类似的东西

    :tag, isequal, "logspout"       /var/log/munin.log
    

    如果您的选项-log-opt tag="logspout" 具有设置系统日志标签属性的效果,或者可能

    :msg, contains, "munin-server"    /var/log/munin.log
    

    :programname, startswith, "munin-server"    /var/log/munin.log
    

    取决于此字符串在记录项中出现的位置。确保在第 1 列中启动选择器。

    【讨论】:

      最近更新 更多