1
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
Note the convenient property ConversionPattern
.
I managed to put something similar to work on 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
This works and writes messages in standard RFC5424 format:
May 14 14:31:36 [server] [app]: Minha mensagem de log
What I really want is a message with priority information as well as entire Traces stack:
May 14 14:31:36 [server] [app]: ERROR Minha mensagem de log MyException
at package1.MyClass.method1(MyClass.java:20)
at ...
It seems that Loggerfields should do this, but I can’t make it work:
loggerFields:
LoggerFields:
KeyValuePair:
key: priority
value: "%p"
KeyValuePair:
key: exception
value: "%ex"
How can I make log4j2 write in syslog using the desired format?