I want to be able to have some of the fields that get generated by logstash logback encoder to be wrapped within another field. Can this be done by the XML configuration inside of logback-spring.xml or do I have to implement some class and then refer to this in the configuration?
I tried reading about implementing the Factory and Decorator methods but it didn't seem to get me anywhere.
<appender name="FILE"
class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>/Users/name/dev/test.log
</file>
<rollingPolicy
class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!-- daily rollover -->
<fileNamePattern>/Users/name/dev/log/test.%d{yyyy-MM-dd}.log
</fileNamePattern>
<maxHistory>30</maxHistory>
</rollingPolicy>
<encoder class="net.logstash.logback.encoder.LogstashEncoder">
<customFields>{"component":"webserver","datacenter":"ord"}
</customFields>
</encoder>
</appender>
The current JSON I get when something logs is:
{
"@timestamp": "2019-07-18T18:12:49.431-07:00",
"@version": "1",
"message": "Application shutdown requested.",
"logger_name": "org.springframework.boot.admin.SpringApplicationAdminMXBeanRegistrar$SpringApplicationAdmin",
"thread_name": "RMI TCP Connection(2)-127.0.0.1",
"level": "INFO",
"level_value": 20000,
"component": "webserver",
"datacenter": "ord"
}
What I want it to be is:
{
"@timestamp": "2019-07-18T18:12:49.431-07:00",
"@version": "1",
"component": "webserver",
"datacenter": "ord",
"data": {
"message": "Application shutdown requested.",
"logger_name": "org.springframework.boot.admin.SpringApplicationAdminMXBeanRegistrar$SpringApplicationAdmin",
"thread_name": "RMI TCP Connection(2)-127.0.0.1",
"level": "INFO",
"level_value": 20000
}
}
As you can see a select set of fields are wrapped withiin 'data' instead of being in outer later.