gpt4 book ai didi

configuration - 使用 rsyslog 将 msg 属性更改为新值

转载 作者:行者123 更新时间:2023-12-01 12:47:23 24 4
gpt4 key购买 nike

我有这个 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
& ~

如何在此配置中更改我接收的 $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")

有关 rsyslog 中的 CEE/lumberjack 属性的更多信息,请参阅 http://www.rsyslog.com/how-to-set-variables-in-rsyslog-v7/ .

关于configuration - 使用 rsyslog 将 msg 属性更改为新值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14607521/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com