Open sdavids opened 2 months ago
A workaround is to set log4j2.julLoggerAdapter
to org.apache.logging.log4j.jul.CoreLoggerAdapter
:
cat << 'EOF' >lib/build.gradle.kts
plugins {
`java-library`
}
repositories {
mavenCentral()
}
dependencies {
api(libs.commons.math3)
implementation(libs.guava)
}
testing {
suites {
val test by getting(JvmTestSuite::class) {
useJUnitJupiter("5.10.3")
dependencies {
runtimeOnly("org.apache.logging.log4j:log4j-core:2.24.0")
runtimeOnly("org.apache.logging.log4j:log4j-jul:2.24.0")
}
targets {
all {
testTask.configure {
systemProperty("java.util.logging.manager", "org.apache.logging.log4j.jul.LogManager")
systemProperty("log4j2.julLoggerAdapter", "org.apache.logging.log4j.jul.CoreLoggerAdapter")
}
}
}
}
}
}
java {
toolchain {
languageVersion = JavaLanguageVersion.of(21)
}
}
EOF
$ git diff
diff --git i/lib/build.gradle.kts w/lib/build.gradle.kts
index 8448ac8..16a5ea2 100644
--- i/lib/build.gradle.kts
+++ w/lib/build.gradle.kts
@@ -24,6 +24,7 @@ testing {
all {
testTask.configure {
systemProperty("java.util.logging.manager", "org.apache.logging.log4j.jul.LogManager")
+ systemProperty("log4j2.julLoggerAdapter", "org.apache.logging.log4j.jul.CoreLoggerAdapter")
}
}
}
$ git add -A && git commit -q -m 'log4j2.julLoggerAdapter'
$ ./gradlew -q test --rerun-tasks
setLevel:92, ApiLogger (org.apache.logging.log4j.jul)
install:110, JavaUtilLoggingSystem (org.gradle.internal.logging.source)
startCapture:73, JavaUtilLoggingSystem (org.gradle.internal.logging.source)
start:330, DefaultLoggingManager$StartableLoggingSystem (org.gradle.internal.logging.services)
start:81, DefaultLoggingManager (org.gradle.internal.logging.services)
1 hidden frame
call:115, SystemApplicationClassLoaderWorker (org.gradle.process.internal.worker.child)
3 hidden frames
The issue is in the backlog of the relevant team, but the existence of a workaround means it might take a while before a fix is made.
See workaround above
This is caused by Gradle logging setup leaking in the test workers. This should not happen in a way that limits logging options for user code tests.
The unfortunate side effect of using the workaround is that you mask the ERRORs raised by you own code—they then turn up during production.
Current Behavior
Upgrading to log4j2 2.24.0 will print ERRORs to the console when executing tests:
To be clear:
The ERRORs come from Gradle setting up its logging plumbing.
Expected Behavior
No ERRORs.
Context
https://logging.apache.org/log4j/2.x/log4j-jul.html#log4j2.julLoggerAdapter
Self-contained Reproducer Project
Gradle version
8.10.1