LoggerFields的系统日志(输出日志优先级和堆栈跟踪)(LoggerFields for S

2019-10-23 02:35发布

Log4j的可以使用系统日志的appender(日志发送到Papertrail 文档 ):

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

注意得心应手ConversionPattern财产。


我设法得到的东西同样的轧制,为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 

它的工作原理和使用默认RFC5424格式输出:

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

我真正想要的是优先级信息,以及完整的堆栈跟踪信息:

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

貌似LoggerFields是应该做的,但我不能得到它的工作:

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

我怎样才能得到Log4j2输出使用所需的格式为syslog?

Answer 1:

请尝试设置RFC5424Layout的exceptionPattern属性%ex



文章来源: LoggerFields for Syslog (output log priority and stack trace)