rsyslog如何自定义模板

在rsyslog配置文件中定义模板
/etc/rsyslog.conf

1.添加模板
以下内容是自定义的模板

$template templateName, “%$Year% %timestamp:1:10:date-rfc3339% UserDefineTAG %MSG% %structured-date% n\%


参数解释


templateName 模板名

%$Year% System Properties,参考https://www.rsyslog.com/doc/v7-stable/configuration/properties.html
$符号不可省略


%timestamp:1:10:date-rfc3339% Message Properties,参考https://www.rsyslog.com/doc/v7-stable/configuration/properties.html
1表示从第一个字符开始,10表示到第10个字符结束。即仅截取timestamp的1到10个字符
Date-rfc3339 属性选项,参考https://www.rsyslog.com/doc/v7-stable/configuration/property_replacer.html


UserDefineTAG 可以直接追加字符,在每一行log中显示
%MSG% 默认syslog协议的消息内容
%structured-data% 有些log的内容使用方括号括上的 例如checkpoint 防火墙的log,[action:denny ……],这些属于structured-data,单独使用MSG是无法显示的。


2.如何使用模板
在LOG文件之后加 ;模板名 即可使用模板
例1. Local0.* /home/log/archive.log;templateName

例2. If $fromhost-ip = ‘xxx.xxx.xxx.xxx’ then /home/log/archive.log;templateName

转载于:https://blog.51cto.com/8577921/2342957

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值