My java application problem is that log4j2 syslog is written not in 'local1.log' but 'messages'. My /etc/rsyslog.conf is configured 'local1.* /var/log/local1.log' in /etc/rsyslog.conf.
But One of weired is when I removed 'appender.syslog.layout.type' and 'appender.syslog.layout.pattern' from log4j2.properties, syslog starts being written in /var/log/local1.log correctly.
Is my configuration incorrect?
Are layout properties not applied in syslog?
[/etc/rsyslog.conf]
# Log anything (except mail) of level info or higher.
# Don't log private authentication messages!
*.info;mail.none;authpriv.none;cron.none;local1.none /var/log/messages
# The authpriv file has restricted access.
authpriv.* /var/log/secure
...
local1.* /var/log/local1.log
[Used log4j2 library]
log4j-api-2.17.2.jar
log4j-core-2.17.2.jar
[log4j2.properties]
status = warn
name = Test
# Console appender configuration
appender.console.type = Console
appender.console.name = consoleLogger
appender.console.layout.type = PatternLayout
appender.console.layout.pattern = %d{HH:mm:ss} %5p (%c{1} - %M:%L) - %m%n
appender.syslog.type = Syslog
appender.syslog.name = sysLogger
appender.syslog.host = localhost
appender.syslog.port = 514
appender.syslog.protocol = UDP
appender.syslog.facility = LOCAL1
appender.syslog.layout.type = PatternLayout
appender.syslog.layout.pattern = %c{1} (%M:%L) %m\n
# Root logger level
rootLogger.level = debug
rootLogger.appenderRefs = consoleLogger, sysLogger
rootLogger.appenderRef.stdout.ref = consoleLogger
rootLogger.appenderRef.syslog.ref = sysLogger
Log4j2's syslog layout is used to format the entire syslog message and must therefore be one of
SyslogLayout(traditional BSD syslog format) orRfc5424Layout(modern syslog layout). Using any other layout will result in invalid messages and RSyslog will have to guess the message's metadata. Most notably the facility will be set toUSER.If you want to send additional data to syslog, beyond
%m, you should use the RFC5424 format and send the additional information as structured data. For example you can use (in XML format):which translates to the properties format as:
Virtually all modern syslog servers can interpret structured data. For RSyslog you need to: