使用log4j 1.2 SyslogAppender在zookeeper日志中转义换行符

时间:2015-10-16 18:16:30

标签: log4j apache-zookeeper syslog rsyslog

我正在运行Apache Zookeeper 3.4.6,后者又使用log4j 1.2.16。我将其日志写入本地rsyslog服务器,这一切都很好。但是,当记录异常消息时,堆栈跟踪将记录为多行消息,这会破坏我的系统日志消息格式。好像SyslogAppender将每一行作为一个单独的系统日志事件发送,这很奇怪,可能是错误的。

我的log4j配置:

log4j.appender.SYSLOG=org.apache.log4j.net.SyslogAppender
log4j.appender.SYSLOG.Threshold=INFO
log4j.appender.SYSLOG.SyslogHost=localhost
log4j.appender.SYSLOG.Facility=Local3
log4j.appender.SYSLOG.layout=org.apache.log4j.PatternLayout
log4j.appender.SYSLOG.layout.ConversionPattern={myhost} zookeeper %m (%c)

我的rsyslog模板:

template(name="LocalFormat" type="list") {
  property(name="timestamp" dateFormat="rfc3339")
  constant(value=" ")
  property(name="hostname")
  constant(value=" ")
  property(name="syslogtag")
  constant(value=" ")
  property(name="msg" spifno1stsp="on" )
  property(name="msg" droplastlf="on" )
  constant(value="\n")
}

$ActionFileDefaultTemplate LocalFormat

有问题的日志消息如下所示:

2015-10-16T18:07:29.023590+00:00 {myhost} zookeeper caught end of stream exception (org.apache.zookeeper.server.NIOServerCnxn)
2015-10-16T18:07:29.023669+00:00 localhost EndOfStreamException: Unable to read additional data from client sessionid 0x0, likely client has closed socket
2015-10-16T18:07:29.023763+00:00 localhost     at org.apache.zookeeper.server.NIOServerCnxn.doIO(NIOServerCnxn.java:228)
2015-10-16T18:07:29.023763+00:00 localhost     at org.apache.zookeeper.server.NIOServerCnxnFactory.run(NIOServerCnxnFactory.java:208)
2015-10-16T18:07:29.023763+00:00 localhost     at java.lang.Thread.run(Thread.java:745)

我希望逃脱换行,但是they don't seem to be an option in log4j 1.2.x。它definitely is in 2.x但我对1.x不太确定。有没有办法在log4j 1.2.x 中执行,即使我不控制记录这些消息的源代码?

0 个答案:

没有答案