log4j multiple SLF4J bindings integration issue

402 views
Skip to first unread message

shishir gowda

unread,
Apr 12, 2017, 4:08:32 PM4/12/17
to Play Framework
Hi,

I am trying replace logback with log4j framework in my java playframework app (2.5.5), and have followed the guides but still see dependency issues wrt logback-classic.

I run it with: sbt -Dlog4j.configurationFile=normal/log4j2.xml

I get the following errors:

SLF4J: Class path contains multiple SLF4J bindings.

SLF4J: Found binding in [jar:file:/Users/shishir/repos/jio-money/jiomoney-wallet-backend/target/universal/stage/lib/ch.qos.logback.logback-classic-1.1.7.jar!/org/slf4j/impl/StaticLoggerBinder.class]

SLF4J: Found binding in [jar:file:/Users/shishir/repos/jio-money/jiomoney-wallet-backend/target/universal/stage/lib/org.apache.logging.log4j.log4j-slf4j-impl-2.4.1.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 [ch.qos.logback.classic.util.ContextSelectorStaticBinder]


My build.sbt file updates are:

lazy val root = (project in file(".")).

  settings(commonSettings: _*).

  disablePlugins(PlayLogback)


libraryDependencies ++= Seq(...

    "org.apache.logging.log4j" % "log4j-slf4j-impl" % "2.4.1" exclude("ch.qos.logback", "logback-classic"),

    "org.apache.logging.log4j" % "log4j-api" % "2.4.1"  exclude("ch.qos.logback", "logback-core"),

    "org.apache.logging.log4j" % "log4j-core" % "2.4.1"

)


My log4j2.xml is:

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

<Configuration status="WARN">

    <Appenders>

        <Console name="console" target="SYSTEM_OUT">

            <PatternLayout pattern="[%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %c{1} - %msg%n"/>

        </Console>

        <File name="file" target="/tmp/app.log">

            <PatternLayout pattern="[%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %c{1} - %msg%n"/>

        </File>

    </Appenders>

    <Loggers>

        <Root level="info" additivity="true">

            <AppenderRef ref="console"/ level="DEBUG">

            <AppenderRef ref="file"/ level="TRACE">

        </Root>

    </Loggers>

</Configuration> 


Please let me know if I am doing anything wrong, or missing anything.

Marcos Pereira

unread,
Apr 18, 2017, 12:57:03 PM4/18/17
to play-fr...@googlegroups.com
Hey, 

Maybe logback is being pulled transitively by another dependency. You can use sbt-dependency-graph to check that.

Best.

--
You received this message because you are subscribed to the Google Groups "Play Framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email to play-framework+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/play-framework/35597e74-a8f8-475e-9a39-5674c7d2f4d2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Marcos Pereira
Software Engineer, Lightbend.com

Will Sargent

unread,
Apr 18, 2017, 1:12:39 PM4/18/17
to Play Framework
You've got two different SLF4J implementations in your classpath somehow.  Something else in your classpath is pulling in a logging engine.

There's a blog post and an example that should help so you can verify you've got the basic project down.

Reply all
Reply to author
Forward
0 new messages