x13*_*x13 3 configuration msg replace rsyslog
我有这个 rsyslog 配置:
$template f_x,"/path/%programname%.%$YEAR%%$MONTH%%$DAY%%$HOUR%.log"
if $programname == 'xyz' and $msg contains 'Hello World' or $msg contains 'FATAL'
then $msg = 'Starting xyz' ?f_x
& ~
Run Code Online (Sandbox Code Playgroud)
如何在此配置中将接收 $msg 属性从 'Hello World' 更改为 $msg = 'BlaBlaBla' 并写入文件 (%programname%.%$YEAR%%$MONTH%%$DAY%%$HOUR%. log) 最后的 $msg 值
提前致谢
您无法覆盖该msg属性。
从 rsyslog 7 开始,您可以通过将 CEE/lumberjack 属性与自定义模板结合使用来实现这一目的。这是一个例子:
# Notice the use of $!msg in template string
template(name="logline" type="string"
string="%TIMESTAMP:::date-rfc3339% %HOSTNAME% %syslogtag%%$!msg:::sp-if-no-1st-sp%%msg:::drop-last-lf%\n")
# If the message matches your conditions, set $!msg to your custom string
if ($programname == 'xyz' and $msg contains 'Hello World' or $msg contains 'FATAL') then set $!msg = "Starting xyz";
# Otherwise, use the msg property value
else set $!msg = $msg;
# Finally, use the custom template
action(type="omfile" file="/tmp/logfile" template="logline")
Run Code Online (Sandbox Code Playgroud)
有关 rsyslog 中的 CEE/lumberjack 属性的更多信息,请参阅http://www.rsyslog.com/how-to-set-variables-in-rsyslog-v7/。
| 归档时间: |
|
| 查看次数: |
11268 次 |
| 最近记录: |