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

标签 configuration replace rsyslog msg

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

相关文章:

javascript - 文本替换后 contentEditable div 没有焦点

MySQL 搜索和替换正则表达式

c++ - 如何配置系统日志以便应用程序日志转到特定文件

linux - 远程 rsyslog 输出中的省略号

linux - 如何解决linux上的空/var/log/secure/var/log/messages等日志问题

apache - 预期 </VirtualHost> 但看到 </Directory>

configuration - 关闭特定文件的 eslint 规则

mysql - Rails - 按模型中的商店属性搜索

c - 用 '%20' 替换字符串中的所有空格。假设字符串在字符串末尾有足够的空间来容纳额外的字符

java - 如何在 Heroku 上以开发模式运行 Play Framework 2 应用程序?