Gradle + Logback external logging problem with MDC initializations


(Pavel Alexeev) #1

Hello.

More generic request abandoned: Logback.xml versus gradle build

So, I have try implement some specific - just to use Logback directly configure them. Please look at example project: https://github.com/Hubbitus/gradle-logback-problem-example-project

It mostly works, but without MDC. It looks like it loaded in different classloader:

buildSrc/gradle.build:

repositories {
    mavenCentral()
}
dependencies {
    compile "ch.qos.logback:logback-classic:1.2.3"
}

When I run it:
./gradlew testLogback

> Task :testLogback
Hello from buildSrc!
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.
2018-11-05 03:59:45,345 [Task worker for ':'] [mdc_test:-] INFO  qwerty.sayHello:36 - ExtLog logger initialization
2018-11-05 03:59:45,356 [Task worker for ':'] [mdc_test:-] INFO  qwerty.sayHello:39 - MDC.mdcAdapter=[org.slf4j.helpers.NOPMDCAdapter@16b5ecf4], StaticMDCBinder.SINGLETON.getMDCA()=[ch.qos.logback.classic.util.LogbackMDCAdapter@5e1c85d6]

As you see there LogbackMDCAdapter found, but not in scope of MDC.<cinit>!