LoggerFields for Syslog (output log priority and stack trace)

孤者浪人 提交于 2020-01-05 04:51:30

问题


Log4j can send logs to Papertrail using a syslog appender (documentation):

log4j.appender.syslog=org.apache.log4j.net.SyslogAppender
log4j.appender.syslog.Facility=LOCAL7 
log4j.appender.syslog.FacilityPrinting=false 
log4j.appender.syslog.Header=true 
log4j.appender.syslog.SyslogHost=<host>.papertrailapp.com:XXXXX
log4j.appender.syslog.layout=org.apache.log4j.PatternLayout 
log4j.appender.syslog.layout.ConversionPattern=%p: (%F:%L) %x %m %n

Notice the handy ConversionPattern property.


I have managed to get something similar rolling for log4j2:

Syslog:
  name: Syslog
  id: [my-id]
  appName: [my-app]
  protocol: UDP
  format: RFC5424
  facility: local7
  host: <host>.papertrailapp.com
  port: XXXXX
  includeMDC: true
  mdcId: mdc 

It works and outputs using the default RFC5424 format:

May 14 14:31:36 [server] [app]: My log message

What I really want is a message with priority information as well as full stack traces:

May 14 14:31:36 [server] [app]: ERROR My log message MyException
        at package1.MyClass.method1(MyClass.java:20)
        at ...

Looks like LoggerFields is supposed to do it, but I can't get it to work:

 loggerFields:
   LoggerFields:
     KeyValuePair:
       key: priority
       value: "%p"
     KeyValuePair:
       key: exception
       value: "%ex"

How can I get Log4j2 to output to syslog using the desired format?


回答1:


Please try setting RFC5424Layout's exceptionPattern attribute to %ex.



来源:https://stackoverflow.com/questions/30244901/loggerfields-for-syslog-output-log-priority-and-stack-trace

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!