Prabhakar Manthena
Prabhakar Manthena

Reputation: 2303

slf4j and log4j logging file is not appending

I have a problem with slf4j and log4j.. I can see the log messages in the console but those messages are not appending to the file

i am using the following jars.

slf4j-log4j12-1.7.5.jar
slf4j-api-1.7.1.jar
log4j-1.2.17.jar

My log4j.properties file is below.

    # Root logger option
    log4j.rootLogger=INFO, file

    # Direct log messages to a log file
    log4j.appender.file=org.apache.log4j.RollingFileAppender
    log4j.appender.file.File=C:\\myLogFile.log
    log4j.appender.file.MaxFileSize=1MB
    log4j.appender.file.MaxBackupIndex=1
    log4j.appender.file.layout=org.apache.log4j.PatternLayout
    log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss}
 %-5p %c{1}:%L - %m%n

and I am getting the following warning in console when i am running my java class

SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/C:/Users/1018835/.m2/repository/ch/qos/logback/logback-classic/1.0.10/logback-classic-1.0.10.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/C:/Users/1018835/.m2/repository/org/slf4j/slf4j-log4j12/1.7.5/slf4j-log4j12-1.7.5.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]

can any one help me on this? thanks in advance.

Upvotes: 4

Views: 1848

Answers (1)

Sanjeev
Sanjeev

Reputation: 9946

If you want to use log4j then keep this binding only. Remove logback-classic-1.0.10.jar from your classpath. As the log is telling that there are multiple bindings in your classpath.

This is excerpt from slf4j site:

SLF4J API is designed to bind with one and only one underlying logging framework at a time. If more than one binding is present on the class path, SLF4J will emit a warning, listing the location of those bindings.

When multiple bindings are available on the class path, select one and only one binding you wish to use, and remove the other bindings. For example, if you have both slf4j-simple-1.7.7.jar and slf4j-nop-1.7.7.jar on the class path and you wish to use the nop (no-operation) binding, then remove slf4j-simple-1.7.7.jar from the class path.

Upvotes: 1

Related Questions