Linux中[r]syslog的#012问题


=Start=

缘由:

在使用[r]syslog时,发现了一个比较怪异的问题,日志中有「#012」这样的字符,但是我之前在操作的时候明明没有发送/打印「#012」啊?还有就是,我的换行符哪去了???

正文:

参考解答:

默认情况下 rsyslog 会将”怪异的”字符(ASCII < 32)进行转义,这其中就包括了换行符(\n)、制表符(\t)等符号,如果你不希望rsyslog自动进行转义,可以在配置文件中进行修改。rsyslog by default escapes all weird characters (ASCII < 32), and this include newlines (as well as tabs and others). Simply add this to your rsyslog config to turn this off:

$EscapeControlCharactersOnReceive off

另一种可选的方法就是——保持syslog的完整性,只在分析日志的时候对特殊字符进行替换。Alternatively, if you want to keep your syslog intact on one line for parsing, you can just replace the characters when viewing the log:

tail -f /var/log/syslog | sed 's/#012/\n\t/g'
tail -f /var/log/syslog | perl -pe 's/#012/\n\t/g;'

参考链接:

=END=

, ,

《“Linux中[r]syslog的#012问题”》 有 1 条评论

回复 hi 取消回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注