logback encoder that uses avaje-jsonb to log events as json
Add the encoder to your appender
<appender name="app" class="your.appender.class"> <encoder class="io.avaje.logback.encoder.JsonbEncoder"> <-- configuration --> </encoder> </appender>To ensure jlink correctly determines the runtime modules required, add the following to your module-info.java:
module my.module { requires io.avaje.logback.encoder; }Add custom fields that will appear in every LoggingEvent like this :
<encoder class="io.avaje.logback.encoder.JsonbEncoder"> <customFields>{"appname":"myWebservice","roles":["customerorder","auth"],"buildinfo":{"version":"Version 0.1.0-SNAPSHOT","lastcommit":"75473700d5befa953c45f630c6d9105413c16fe1"}}</customFields> </encoder>By default, timestamps are written as string values in the format specified by DateTimeFormatter.ISO_OFFSET_DATE_TIME (e.g. 2019-11-03T10:15:30.123+01:00), in the default TimeZone of the host Java platform.
You can change the pattern like this:
<encoder class="io.avaje.logback.encoder.JsonbEncoder"> <timestampPattern>yyyy-MM-dd'T'HH:mm:ss.SSS</timestampPattern> </encoder>The value of the timestampPattern can be any of the following:
constant- (e.g.ISO_OFFSET_DATE_TIME) timestamp written using the givenDateTimeFormatterconstant- any other value - (e.g.
yyyy-MM-dd'T'HH:mm:ss.SSS) timestamp written using aDateTimeFormattercreated from the given pattern
The formatter uses the default TimeZone of the host Java platform by default. You can change it like this:
<encoder class="io.avaje.logback.encoder.JsonbEncoder"> <timeZone>UTC</timeZone> </encoder>The value of the timeZone element can be any string accepted by java's TimeZone.getTimeZone(String id) method. For example America/Los_Angeles, GMT+10 or UTC. Use the special value [DEFAULT] to use the default TimeZone of the system.