'java.lang.ClassNotFoundException: net.logstash.logback.encoder.LogstashEncoder

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 .



Solution 1:[1]

I got the same problem in Jenkins. But I was not doing the logging in json format. I used akka-http, which had SLF4J/logback for logging.

And this logback.xml fixed my problem:

<configuration>
     <appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
         <target>System.out</target>
         <encoder>
             <pattern>%X{akkaTimestamp} %-5level[%thread] %logger{0} - %msg%n</pattern>
         </encoder>
     </appender>

     <appender name="FILE" class="ch.qos.logback.core.FileAppender">
         <file>akka.log</file>
         <append>true</append>
         <encoder>
             <pattern>%date{yyyy-MM-dd} %X{akkaTimestamp} %-5level[%thread] %logger{1} - %msg%n</pattern>
         </encoder>
     </appender>

     <logger name="akka" level="DEBUG"/>

     <root level="DEBUG">
         <appender-ref ref="CONSOLE"/>
         <appender-ref ref="FILE"/>
     </root>
 </configuration>

Not sure will it fix your problem or not. Would love to know more details about the problem.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Java Xu