sbt-assembly: Logback does not work with über-JAR

Viewed 24

If I run the application within IntelliJ, logging works fine, but if I run the über-JAR, I get the following error:

LF4J: No SLF4J providers were found.
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#noProviders for further details.

I use the following configuration to build my über-JAR with sbt-assembly:

lazy val app = (project in file("."))
  .settings(
    assembly / mainClass := Some("com.example.app.Main"),
    assembly / assemblyJarName := "gcm.jar",
    assembly / assemblyMergeStrategy := {
      case PathList("META-INF", xs@_*) => MergeStrategy.discard
      case PathList("reference.conf") => MergeStrategy.concat
      case x => MergeStrategy.first
    }
  )

The dependencies for Logback and scala-logging would be:

ThisBuild / libraryDependencies += "ch.qos.logback" % "logback-classic" % "1.4.0"
ThisBuild / libraryDependencies += "com.typesafe.scala-logging" %% "scala-logging" % "3.9.5"

The logback.xml:

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration>

<configuration>
    <import class="ch.qos.logback.classic.encoder.PatternLayoutEncoder"/>
    <import class="ch.qos.logback.core.ConsoleAppender"/>
    <import class="ch.qos.logback.core.FileAppender"/>

    <appender name="STDOUT" class="ConsoleAppender">
        <encoder class="PatternLayoutEncoder">
            <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{0} - %msg%n</pattern>
        </encoder>
    </appender>
    <appender name="FILE" class="FileAppender">
        <file>gcm.log</file>
        <append>true</append>
        <immediateFlush>true</immediateFlush>
        <encoder class="PatternLayoutEncoder">
            <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{0} - %msg%n</pattern>
        </encoder>
    </appender>

    <root level="debug">
        <appender-ref ref="STDOUT"/>
        <appender-ref ref="FILE"/>
    </root>
</configuration>

..

0 Answers
Related