如何将原始消息仅存储到文件中?
例如:
我通过 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 配置来从输入中提取原始消息,没有 syslog 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
关于linux - rsyslog 配置仅将原始消息 ($msg) 存储到文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37023745/