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 .

3

1 Answer

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Chloe Bennett

Chloe Bennett

Culture, Media & Entertainment Columnist

Chloe Bennett explores the intersection of pop culture, streaming entertainment, digital trends, and contemporary lifestyle. Her weekly commentary reaches thousands of culture enthusiasts.

Share this article
Twitter Facebook Pinterest