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 ConversionPattern
property.
I was able to put something similar to work in 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 the 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 stack traces:
May 14 14:31:36 [server] [app]: ERROR Minha mensagem de log MyException
at package1.MyClass.method1(MyClass.java:20)
at ...
It seems like LoggerFields should do this, but I can not get it to work :
loggerFields:
LoggerFields:
KeyValuePair:
key: priority
value: "%p"
KeyValuePair:
key: exception
value: "%ex"
How can I make log4j2 write to syslog using the desired format?