Log files slf4j and log4j are not added

I have a problem with slf4j and log4j .. I see log messages in the console, but these messages are not added to the file

I use the following cans.

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 get the following warning in the console when I run 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 someone help me with this? thanks in advance.

+4
source share
1 answer

If you want to use log4j, save this binding. Remove logback-classic-1.0.10.jarfrom classpath. Because the magazine reports that there is multiple bindings in your classpath.

This is an excerpt from the slf4j site :

API SLF4J . , SLF4J .

, , , . , slf4j-simple-1.7.7.jar, slf4j-nop-1.7.7.jar , nop (no-operation), slf4j-simple- 1.7.7.jar .

+1

Source: https://habr.com/ru/post/1543385/


All Articles