skip to Main Content

If I use any 1.3.x or 1.4.x logback-classic version, my application stops logging.
The logback.xml file maybe isn’t even loaded (if I insert invalid xml or delete it, I get no errors).

It works fine with logback 1.2.11.

I’m using gradle automatic dependency resolution so I shouldn’t have messed them.

This works:

logback-classic-1.2.11.jar + logback-core-1.2.11.jar + slf4j-api-1.7.32.jar

This doesn’t work:

logback-classic-1.3.3.jar + logback-core-1.3.3.jar + slf4j-api-2.0.1.jar

java 8 on windows 10 in Eclipse 2022-09 (4.25.0)

My classpath:

activation-1.1.jar
annotations-13.0.jar
antlr-2.7.7.jar
attoparser-2.0.5.RELEASE.jar
byte-buddy-1.10.22.jar
checker-compat-qual-2.5.5.jar
checkout-sdk-1.0.5.jar
classmate-1.5.1.jar
commons-beanutils-1.9.4.jar
commons-codec-1.11.jar
commons-collections-3.2.2.jar
commons-configuration2-2.8.0.jar
commons-exec-1.3.jar
commons-fileupload-1.3.3.jar
commons-io-2.11.0.jar
commons-jxpath-1.3.jar
commons-lang3-3.12.0.jar
commons-logging-1.2.jar
commons-text-1.9.jar
concurrentlinkedhashmap-lru-1.4.2.jar
error_prone_annotations-2.5.1.jar
failureaccess-1.0.1.jar
FastInfoset-1.2.15.jar
flyway-core-5.0.5.jar
google-api-client-1.32.1.jar
google-api-client-jackson2-1.32.1.jar
google-http-client-1.39.2.jar
google-http-client-apache-v2-1.39.2.jar
google-http-client-gson-1.39.2.jar
google-oauth-client-1.31.5.jar
grpc-context-1.27.2.jar
gson-2.8.6.jar
guava-30.1.1-android.jar
hamcrest-core-1.3.jar
hibernate-commons-annotations-5.1.2.Final.jar
hibernate-core-5.5.0.Final.jar
hibernate-entitymanager-5.5.0.Final.jar
hibernate-validator-5.4.2.Final.jar
httpclient-4.5.13.jar
httpcore-4.4.14.jar
istack-commons-runtime-3.0.7.jar
j2objc-annotations-1.3.jar
jackson-annotations-2.12.7.jar
jackson-core-2.12.7.jar
jackson-databind-2.12.7.jar
jandex-2.2.3.Final.jar
javassist-3.27.0-GA.jar
javax.activation-api-1.2.0.jar
javax.inject-1.jar
javax.mail-1.6.2.jar
javax.persistence-api-2.2.jar
jaxb-api-2.3.1.jar
jaxb-runtime-2.3.1.jar
jboss-logging-3.4.2.Final.jar
jboss-transaction-api_1.2_spec-1.1.1.Final.jar
jsoup-1.9.2.jar
jsr305-3.0.2.jar
junit-4.13.2.jar
kotlin-stdlib-1.5.0.jar
kotlin-stdlib-common-1.5.0.jar
kotlin-stdlib-jdk7-1.5.0.jar
kotlin-stdlib-jdk8-1.5.0.jar
listenablefuture-9999.0-empty-to-avoid-conflict-with-guava.jar
logback-classic-1.3.3.jar
logback-core-1.3.3.jar
metadata-extractor-2.16.0.jar
mysql-connector-java-8.0.25.jar
mysql-connector-java-8.0.30.jar
opencensus-api-0.28.0.jar
opencensus-contrib-http-util-0.28.0.jar
paypalhttp-1.0.3.jar
protobuf-java-3.11.4.jar
protobuf-java-3.19.4.jar
selenium-api-3.8.1.jar
selenium-chrome-driver-3.8.1.jar
selenium-firefox-driver-3.8.1.jar
selenium-remote-driver-3.8.1.jar
selenium-support-3.8.1.jar
slf4j-api-2.0.1.jar
spring-aop-5.3.18.jar
spring-beans-5.3.18.jar
spring-context-5.3.18.jar
spring-context-support-5.3.18.jar
spring-core-5.3.18.jar
spring-expression-5.3.18.jar
spring-jcl-5.3.18.jar
spring-jdbc-5.3.18.jar
spring-orm-5.3.18.jar
spring-security-config-5.5.0.jar
spring-security-core-5.5.0.jar
spring-security-crypto-5.5.0.jar
spring-security-web-5.5.0.jar
spring-social-config-1.1.4.RELEASE.jar
spring-social-core-1.1.4.RELEASE.jar
spring-social-facebook-2.0.3.RELEASE.jar
spring-social-web-1.1.4.RELEASE.jar
spring-tx-5.3.18.jar
spring-web-5.3.18.jar
spring-webmvc-5.3.18.jar
stax-ex-1.8.jar
thymeleaf-3.0.15.RELEASE.jar
thymeleaf-extras-springsecurity5-3.0.4.RELEASE.jar
thymeleaf-spring5-3.0.15.RELEASE.jar
tomcat-annotations-api-8.5.82.jar
tomcat-embed-core-8.5.82.jar
tomcat-servlet-api-8.0.48.jar
tomcat-servlet-api-8.5.82.jar
txw2-2.3.1.jar
unbescape-1.1.6.RELEASE.jar
validation-api-1.1.0.Final.jar
vibur-dbcp-25.0.jar
vibur-object-pool-25.0.jar
xmpcore-6.1.11.jar

EDIT:

These few lines in build.gradle make the difference between working and not working:

implementation('ch.qos.logback:logback-classic') {
    version {
        strictly '1.2.11'
    }
}

EDIT:

This is the console output. None of it is logged by me. The "!!!!!" line is printed with System.out.println() as suggested and is black, all the rest is red:

SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
nov 16, 2022 7:05:18 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-nio-8080"]
nov 16, 2022 7:05:18 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["ajp-nio-0.0.0.0-8009"]
nov 16, 2022 7:05:18 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["https-jsse-nio-8443"]
nov 16, 2022 7:05:19 PM org.apache.catalina.core.StandardService startInternal
INFO: Starting service [Tomcat]
nov 16, 2022 7:05:19 PM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet engine: [Apache Tomcat/8.5.83]
nov 16, 2022 7:05:19 PM org.apache.catalina.startup.ContextConfig getDefaultWebXmlFragment
INFO: No global web.xml found
nov 16, 2022 7:05:24 PM org.apache.catalina.core.ApplicationContext log
INFO: 2 Spring WebApplicationInitializers detected on classpath
nov 16, 2022 7:05:24 PM org.apache.catalina.core.ApplicationContext log
INFO: Initializing Spring root WebApplicationContext
SLF4J: Failed to load class "org.slf4j.impl.StaticMDCBinder".
SLF4J: Defaulting to no-operation MDCAdapter implementation.
SLF4J: See http://www.slf4j.org/codes.html#no_static_mdc_binder for further details.
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
nov 16, 2022 7:05:35 PM org.apache.catalina.core.ApplicationContext log
INFO: Initializing Spring DispatcherServlet 'dispatcher'
nov 16, 2022 7:05:36 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-nio-8080"]
nov 16, 2022 7:05:36 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["ajp-nio-0.0.0.0-8009"]
nov 16, 2022 7:05:36 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["https-jsse-nio-8443"]

2

Answers


  1. Chosen as BEST ANSWER

    TLDR: Eclipse was adding slf4j-api-1.7.25 to the classpath because thymeleaf-3.0.15.RELEASE depended on it, ignoring the forced upgrade to slf4j-api-2.0.1.jar required by logback-classic:1.3.3. Fixed by updating to thymeleaf-3.1.0.RELEASE

    There must be some bug in the Gradle dependency resolution used by Eclipse because the dependency of thymeleaf-3.0.15.RELEASE from slf4j-api-1.7.25 was not "totally" upgraded to slf4j-api-2.0.1.jar contrary to what is shown both by the Eclipse "Project and External Dependencies" tree and the manual gradle dependencyInsight command:

    org.slf4j:slf4j-api:1.7.25 -> 2.0.1
    +--- org.thymeleaf:thymeleaf:3.0.15.RELEASE
    |    --- org.thymeleaf:thymeleaf-spring5:3.0.15.RELEASE
    |         --- compileClasspath
    

    In reality slf4j-api-1.7.25.jar was still used together with slf4j-api-2.0.1.jar but was visible only on the command line that you can get from the Eclipse "Run Configurations" > "Show Command Line" button.

    This failure to upgrade a dependency doesn't always happen. In my case I had a ProjectMain depending on a ProjectLib and while both used thymeleaf-3.0.15.RELEASE just the former had a dependency on logback-classic:1.3.3 that was upgrading slf4j-api-1.7.25.jar to slf4j-api-2.0.1.jar.

    EDIT:

    Forcing the use of slf4j-api-2.0.1.jar on the main project doesn't prevent Eclipse from adding the old jar on the command line if the lib project still depends on it:

    implementation('org.slf4j:slf4j-api') {
        version {
            strictly '2.0.1'
        }
    }
    

  2. My two cents: are you using nested appenders in your configuration? If yes, this construct is not supported anymore since Logback 1.3 and your appenders may simply not be initialized. See LOGBACK-1674 for more information.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search