I am new to Scala and I am trying to generate logs in json format for an existing sbt project, but i am getting the error below -
java.lang.ClassNotFoundException: net.logstash.logback.encoder.LogstashEncoder
I have added these dependencies to the build.sbt
"net.logstash.logback" % "logstash-logback-encoder" % "4.11",
"ch.qos.logback" % "logback-core" % "1.2.3",
"ch.qos.logback" % "logback-access" % "1.2.3"
and my logback.xml looks like this -
<configuration>
<appender name="FILE" class="ch.qos.logback.core.FileAppender">
<file>app.log</file>
<append>true</append>
<!--<encoder>
<pattern>%date{yyyy-MM-dd} %X{akkaTimestamp} %-5level[%thread] %logger{1} - %msg%n</pattern>
</encoder>-->
<encoder class="net.logstash.logback.encoder.LogstashEncoder"/>
</appender>
<root level="DEBUG">
<appender-ref ref="FILE"/>
</root>
</configuration>
Scala Version 2.12.3 SBT Version 1.0.3
Where I might be going wrong, any help will be appreciated .
I got same problem while building spring boot application.
I had defined encoder in logback-spring.xml
<encoder class="net.logstash.logback.encoder.LoggingEventCompositeJsonEncoder">
The error message states that the required class cannot be found in the class path
java.lang.ClassNotFoundException: net.logstash.logback.encoder.LoggingEventCompositeJsonEncoder
In my case the problem was maven didn't fetch the dependencies which I modified in pom.xml for this encoder.
<dependency>
<groupId>net.logstash.logback</groupId>
<artifactId>logstash-logback-encoder</artifactId>
<version>7.4</version>
</dependency>
So, just make sure to perform mvn clean install and verify if the dependency can be seen in the external libraries

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With