1. In pom.xml, add the dependency

<dependency>
<groupId>net.logstash.logback</groupId>
<artifactId>logstash-logback-encoder</artifactId>
<version>4.6</version>
</dependency>

2. In logback.xml, add the LogstashEncoder appender

 <appender name=”JSON” class=”ch.qos.logback.core.rolling.RollingFileAppender”>

//This is the JSON formatter
<encoder class=”net.logstash.logback.encoder.LogstashEncoder” />

//This is where the JSON log will be produced
<file>${catalina.base}/logs/webapp.log.json</file>

//On a daily basis, the JSON logged will be rolled over
<rollingPolicy class=”ch.qos.logback.core.rolling.TimeBasedRollingPolicy”>
<fileNamePattern>${catalina.base}/logs/webapp.log.json.%d{yyyy-MM-dd}</fileNamePattern>

//We only store the rolled over log for a max of 7 days
<maxHistory>7</maxHistory>
</rollingPolicy>
</appender>

3. Add the appender to the Root Level

<root level=”DEBUG”>
<appender-ref ref=”JSON” />
</root>