【问题标题】:extending rsyslog's default logging template扩展 rsyslog 的默认日志记录模板
【发布时间】:2019-09-13 00:32:17
【问题描述】:

使用 centos 7,我想扩展 rsyslogs 标准模板。

我其实不知道,默认模板是硬编码的还是在配置文件中显式定义的?

无论如何,使用标准会产生这样的结果: Sep 11 14:01:01 <hostname> root: Hello from /etc/cron.hourly/test_hourly

我想扩展它,让它变成这样: Sep 11 14:01:01 <hostname> local1.notice root: Hello from /etc/cron.hourly/test_hourly

换句话说,我想包含文本“local1.notice”, “local1.notice”只是一个例子, 这是我使用rsyslogs-predefined variables: %syslogfacility-text%.%syslogseverity-text%时的结果

我已经尝试过使用新模板, 通过在我的 /etc/rsyslig.conf 中包含以下两行

$template sample_template,"%timegenerated% %HOSTNAME% %syslogfacility-text%.%syslogseverity-text% %msg%\n" local1.* /var/log/local1.log;sample_template

但是这种方法会导致这样的行:

Sep 11 10:01:01 <hostname> local1.notice Hello from /etc/cron.hourly/test_hourly
Sep 11 14:01:01 <hostname> local1.notice root: Hello from /etc/cron.hourly/test_hourly

如您所见,root: - 部分丢失了。

谢谢。

【问题讨论】:

    标签: linux rsyslog


    【解决方案1】:

    回答我自己的问题,

    %syslogtag%
    

    条目只是丢失了......

    也将语法更改为新模板配置语法, 这是我的 /etc/rsyslog.conf 中的结果行

    # old:
    # Use default timestamp format
    # $ActionFileDefaultTemplate RSYSLOG_TraditionalFileFormat
    # new:
    template (name="sample_template" type="string" string="%timegenerated% %HOSTNAME% %syslogfacility-text%.%syslogseverity-text% %syslogtag% %msg%\n")
    $ActionFileDefaultTemplate sample_template
    

    【讨论】:

      猜你喜欢
      • 2019-04-09
      • 2011-07-23
      • 2019-01-07
      • 2021-10-04
      • 2013-12-29
      • 2018-01-24
      • 2017-07-14
      • 2016-01-07
      • 2014-11-06
      相关资源
      最近更新 更多