Search code examples
scalaloggingsbtlogbackslf4j

logback.xml does not used


I'm trying to use logback.xml in my sbt project. I added the following dependency:

"ch.qos.logback" % "logback-classic" % "1.2.3"

I created a logback.xml and located it under:

/src/main/resources

When I run it on Intellij, sometimes it works and sometimes it doesn't work. When I run the jar (not Uber jar), it always doesn't work:

SLF4J: Found binding in [jar:file:/Users/***/.ivy2/cache/org.slf4j/slf4j-log4j12/jars/slf4j-log4j12-1.7.16.jar!/org/slf4j/impl/StaticLoggerBinder.class] 
SLF4J: Found binding in [jar:file:/Users/***/.ivy2/cache/ch.qos.logback/logback-classic/jars/logback-classic-1.2.3.jar!/org/slf4j/impl/StaticLoggerBinder.class] 
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation. SLF4J: Actual binding is of type [org.slf4j.impl.Log4jLoggerFactory]

I believe the issue is related to classpath issue, excluded SLF4J, specified the logback.xml path explicitly, but nothing!

Please help!


Solution

  • I excluded "org.slf4j" from all dependencies & plugins, except from "ch.qos.logback", and be doing I avoided multiple slf4j in classpath:

    ... .map( _ exclude("org.slf4j", "*")) ++ Seq("ch.qos.logback" % "logback-classic" % "1.2.3")