rsyslog 配置仅将原始消息 ($msg) 存储到文件

rsyslog config to store only raw message ($msg) to a file

我如何才能仅将 原始消息存储到文件中?
例如:
我通过 rsyslog 收到一条消息:

收到系统日志消息:

May  4 13:18:47 xxxx apache-error: [Wed May 04 13:18:41.256596 2016] [:error] [pid 54583] [client 192.168.30.200:52638] script '/var/www/aaa.php' not found or unable to stat

我需要一个 rsyslog 配置 来从输入中提取原始消息,没有系统日志 header(下面突出显示):

May 4 13:18:47 xxxx apache-error: [Wed May 04 13:18:41.256596 2016] [:error] [pid 54583] [client 192.168.30.200:52638] script '/var/www/aaa.php' not found or unable to stat

预期输出:

[Wed May 04 13:18:41.256596 2016] [:error] [pid 54583] [client 192.168.30.200:52638] script '/var/www/aaa.php' not found or unable to stat

谢谢!

您可以在 rsyslog 配置文件中添加自定义模板。所以在/etc/rsyslog.d中找到配置问题日志文件的配置文件。如果您正在谈论系统日志,那么您可以添加自定义模板并将配置行更改为类似以下内容:

$template myFormat,"%msg%\n"
*.*         -/var/log/syslog; myFormat

此外,如果您想要所有日志文件的模板,您可以将其添加到您的 rsyslog 配置文件中,这样您就不必专门将模板添加到您的日志文件行中:

$template myFormat,"%msg%\n"
$ActionFileDefaultTemplate myFormat

推荐使用: $template myFormat,"%msg:2:2048%\n

参考:http://rsyslog-users.1305293.n2.nabble.com/rawmessage-forwarding-doesn-t-appear-to-work-td7482747.html

%msg:2:2048% syslog 事件的消息部分立即开始。