Reputation: 1927
In my spring boot app the following configuration is used for adding JSON logs via logback-spring.xml
:
<configuration>
<include resource="org/springframework/boot/logging/logback/base.xml"/>
<appender name="consoleAppender" class="ch.qos.logback.core.ConsoleAppender">
<encoder class="net.logstash.logback.encoder.LogstashEncoder">
<fieldNames>
<timestamp>time</timestamp>
<message>msg</message>
<thread>thread</thread>
<logger>logger</logger>
<version>[ignore]</version>
<levelValue>[ignore]</levelValue>
</fieldNames>
</encoder>
</appender>
<root level="all">
<appender-ref ref="consoleAppender" />
</root>
</configuration>
However, when running the app both versions of logs (non-JSON & JSON) are traced:
2017-08-08 07:31:49.718 INFO 6849 --- [ main] .s.b.c.e.j.JettyEmbeddedServletContainer : Jetty started on port(s) 10000 (http/1.1)
{"time":"2017-08-08T07:31:49.718+02:00","msg":"Jetty started on port(s) 10000 (http/1.1)","logger":"org.springframework.boot.context.embedded.jetty.JettyEmbeddedServletContainer","thread":"main","level":"INFO","HOSTNAME":"ilya-ThinkPad-X1-Carbon-4th","caller_class_name":"org.springframework.boot.context.embedded.jetty.JettyEmbeddedServletContainer","caller_method_name":"start","caller_file_name":"JettyEmbeddedServletContainer.java","caller_line_number":144}
Is is possible to configure logback / logstash encoder, so that only JSON version would be available in the logs and non-JSON would be skipped ?
Upvotes: 2
Views: 5913
Reputation: 1927
oh, stupid me - one should just remove the line from logback config which adds base logging:
<include resource="org/springframework/boot/logging/logback/base.xml"/>
Upvotes: 4