I'm trying to log Java logs to Syslog in JSON format but I've found a strange issue where the Syslog header is not being set as expected.
I'm testing this on a Mac and using wireshark to grab the packets as they get sent to the UDP 514 port (via loopback interface)
My logback.xml is as follows:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<conversionRule conversionWord="syslogStart" converterClass="ch.qos.logback.classic.pattern.SyslogStartConverter"/>
<appender name="stash" class="net.logstash.logback.appender.LogstashSocketAppender">
<host>localhost</host>
<port>514</port>
<prefix class="ch.qos.logback.core.encoder.LayoutWrappingEncoder">
<layout class="ch.qos.logback.classic.PatternLayout">
<pattern>%syslogStart{LOCAL5}</pattern>
</layout>
</prefix>
</appender>
<root level="INFO">
<appender-ref ref="stash"/>
</root>
</configuration>
and when I look at the output of wireshark I only see the JSON being logged (no PRI header field given)
[truncated]Syslog message: (unknown): {"@timestamp":"2016-03-22T12:13:37.270+11:00","@version":1,"message":"Started App in 4.327 seconds (JVM running for 4.92)","logger_name":"au.com.xxx.App","threa
If I switch to the standard logback Syslog appender (non JSON output)
...
<appender name="SYSLOG" class="ch.qos.logback.classic.net.SyslogAppender">
<syslogHost>127.0.0.1</syslogHost>
<Facility>LOCAL5</Facility>
<SuffixPattern>%-5level MyApp %logger %msg</SuffixPattern>
</appender>
...
I do see the correct header facility raw value <174> and parsed values LOCAL5.INFO in the wireshark packets
Syslog message: LOCAL5.INFO: Mar 22 12:31:03 sbmelmac-06390.local INFO App au.com.App Started App in 11.292 seconds (JVM running for 29.336)
The syslog header is required (in the syslog conf) to route the log messages to the correct files so without this I can't filter out log entries based on facility filters.
I'm using SpringBoot (1.2.7), (which uses logback 1.1.3), apache camel (2.16.1) and logstash-logback-encoder (4.6)
When I run in debug it looks like the SyslogStartConverter.convert method is never invoked.
Cheers Roy