From b6c2a63269286750cfda2e2871dd3a831f4f5b62 Mon Sep 17 00:00:00 2001 From: Brian Marks Date: Mon, 16 Nov 2026 14:21:03 -0500 Subject: [PATCH 1/2] Write JUL config file before the log-injection smoke test app starts JULBackend and JULInterfaceSlf4jToLogbackBackend wrote their java.util.logging.config.file contents in setupSpec. Spock runs the superclass setupSpec first, and ProcessManager.setupSpec starts the child process there and waits for scope diagnostics to be ready. The child's LogManager could read the still-empty temp file, install no handler, and drop every log line, which failed "check raw file injection" with an empty raw log. Write the properties file from additionalArguments(), which runs while the process command is built and before the process starts. --- .../smoketest/LogInjectionSmokeTest.groovy | 40 ++++++++++--------- 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/dd-smoke-tests/log-injection/src/test/groovy/datadog/smoketest/LogInjectionSmokeTest.groovy b/dd-smoke-tests/log-injection/src/test/groovy/datadog/smoketest/LogInjectionSmokeTest.groovy index 272ab6b0b6f..d0bd95e16c8 100644 --- a/dd-smoke-tests/log-injection/src/test/groovy/datadog/smoketest/LogInjectionSmokeTest.groovy +++ b/dd-smoke-tests/log-injection/src/test/groovy/datadog/smoketest/LogInjectionSmokeTest.groovy @@ -479,7 +479,17 @@ abstract class JULBackend extends LogInjectionSmokeTest { false } - def setupSpec() { + def cleanupSpec() { + propertiesFile?.delete() + } + + List additionalArguments() { + // The child's LogManager reads this file at startup, so write it before the process starts + writeJulConfig() + return ["-Djava.util.logging.config.file=${propertiesFile.absolutePath}" as String] + } + + protected void writeJulConfig() { def isWindows = System.getProperty("os.name").toLowerCase().contains("win") def outputLogFilePath = outputLogFile.absolutePath if (isWindows) { @@ -496,14 +506,6 @@ abstract class JULBackend extends LogInjectionSmokeTest { it.println "java.util.logging.SimpleFormatter.format=JUL:%1\$tF %1\$tT [%4\$-7s] - %5\$s%n" } } - - def cleanupSpec() { - propertiesFile?.delete() - } - - List additionalArguments() { - return ["-Djava.util.logging.config.file=${propertiesFile.absolutePath}" as String] - } } class JULInterfaceJULBackend extends JULBackend { @@ -719,22 +721,24 @@ class JULInterfaceSlf4jToLogbackBackend extends LogInjectionSmokeTest { LOGBACK_BACKEND } - def setupSpec() { - // JUL doesn't support reading a properties file from the classpath so everything needs - // to be specified in a temp file - propertiesFile.withPrintWriter { - it.println ".level=INFO" - it.println "handlers=org.slf4j.bridge.SLF4JBridgeHandler" - } - } - def cleanupSpec() { propertiesFile?.delete() } List additionalArguments() { + // The child's LogManager reads this file at startup, so write it before the process starts + writeJulConfig() return ["-Djava.util.logging.config.file=${propertiesFile.absolutePath}" as String] } + + protected void writeJulConfig() { + // JUL doesn't support reading a properties file from the classpath so everything needs + // to be specified in a temp file + propertiesFile.withPrintWriter { + it.println ".level=INFO" + it.println "handlers=org.slf4j.bridge.SLF4JBridgeHandler" + } + } } class JULInterfaceSlf4jToLogbackBackendNoTags extends JULInterfaceSlf4jToLogbackBackend {} From 19bf9a7575133033d43ba1c02a8a88fc8b5220a6 Mon Sep 17 00:00:00 2001 From: Brian Marks Date: Mon, 16 Nov 2026 16:17:17 -0500 Subject: [PATCH 2/2] Share the JUL config file setup between JUL smoke test bases Add JULConfiguredSmokeTest, which owns the temporary java.util.logging.config.file, writes it from additionalArguments() before the process starts, and deletes it in cleanupSpec. JULBackend and JULInterfaceSlf4jToLogbackBackend now only write their handler-specific properties. --- .../smoketest/LogInjectionSmokeTest.groovy | 70 ++++++++----------- 1 file changed, 28 insertions(+), 42 deletions(-) diff --git a/dd-smoke-tests/log-injection/src/test/groovy/datadog/smoketest/LogInjectionSmokeTest.groovy b/dd-smoke-tests/log-injection/src/test/groovy/datadog/smoketest/LogInjectionSmokeTest.groovy index d0bd95e16c8..4fa32046983 100644 --- a/dd-smoke-tests/log-injection/src/test/groovy/datadog/smoketest/LogInjectionSmokeTest.groovy +++ b/dd-smoke-tests/log-injection/src/test/groovy/datadog/smoketest/LogInjectionSmokeTest.groovy @@ -464,10 +464,29 @@ abstract class LogInjectionSmokeTest extends AbstractSmokeTest { } } -abstract class JULBackend extends LogInjectionSmokeTest { +abstract class JULConfiguredSmokeTest extends LogInjectionSmokeTest { + // JUL doesn't support reading a properties file from the classpath so everything needs + // to be specified in a temp file @Shared def propertiesFile = File.createTempFile("julConfig", ".properties") + def cleanupSpec() { + propertiesFile?.delete() + } + + List additionalArguments() { + // The child's LogManager reads this file at startup, so write it before the process starts + propertiesFile.withPrintWriter { + it.println ".level=INFO" + writeJulProperties(it) + } + return ["-Djava.util.logging.config.file=${propertiesFile.absolutePath}" as String] + } + + protected abstract void writeJulProperties(PrintWriter out) +} + +abstract class JULBackend extends JULConfiguredSmokeTest { def backend() { "JUL" } @@ -479,32 +498,17 @@ abstract class JULBackend extends LogInjectionSmokeTest { false } - def cleanupSpec() { - propertiesFile?.delete() - } - - List additionalArguments() { - // The child's LogManager reads this file at startup, so write it before the process starts - writeJulConfig() - return ["-Djava.util.logging.config.file=${propertiesFile.absolutePath}" as String] - } - - protected void writeJulConfig() { + protected void writeJulProperties(PrintWriter out) { def isWindows = System.getProperty("os.name").toLowerCase().contains("win") def outputLogFilePath = outputLogFile.absolutePath if (isWindows) { // FileHandler pattern only uses / as path delimiter outputLogFilePath = outputLogFilePath.replace("\\", "/") } - // JUL doesn't support reading a properties file from the classpath so everything needs - // to be specified in a temp file - propertiesFile.withPrintWriter { - it.println ".level=INFO" - it.println "handlers=java.util.logging.FileHandler" - it.println "java.util.logging.FileHandler.pattern=${outputLogFilePath}" - it.println "java.util.logging.FileHandler.formatter=java.util.logging.SimpleFormatter" - it.println "java.util.logging.SimpleFormatter.format=JUL:%1\$tF %1\$tT [%4\$-7s] - %5\$s%n" - } + out.println "handlers=java.util.logging.FileHandler" + out.println "java.util.logging.FileHandler.pattern=${outputLogFilePath}" + out.println "java.util.logging.FileHandler.formatter=java.util.logging.SimpleFormatter" + out.println "java.util.logging.SimpleFormatter.format=JUL:%1\$tF %1\$tT [%4\$-7s] - %5\$s%n" } } @@ -713,31 +717,13 @@ class Slf4jInterfaceJCLToLog4j2BackendNoTags extends Slf4jInterfaceJCLToLog4j2Ba class Slf4jInterfaceJCLToLog4j2Backend128bTid extends Slf4jInterfaceJCLToLog4j2Backend {} class Slf4jInterfaceJCLToLog4j2LatestBackend extends Slf4jInterfaceJCLToLog4j2Backend {} -class JULInterfaceSlf4jToLogbackBackend extends LogInjectionSmokeTest { - @Shared - def propertiesFile = File.createTempFile("julConfig", ".properties") - +class JULInterfaceSlf4jToLogbackBackend extends JULConfiguredSmokeTest { def backend() { LOGBACK_BACKEND } - def cleanupSpec() { - propertiesFile?.delete() - } - - List additionalArguments() { - // The child's LogManager reads this file at startup, so write it before the process starts - writeJulConfig() - return ["-Djava.util.logging.config.file=${propertiesFile.absolutePath}" as String] - } - - protected void writeJulConfig() { - // JUL doesn't support reading a properties file from the classpath so everything needs - // to be specified in a temp file - propertiesFile.withPrintWriter { - it.println ".level=INFO" - it.println "handlers=org.slf4j.bridge.SLF4JBridgeHandler" - } + protected void writeJulProperties(PrintWriter out) { + out.println "handlers=org.slf4j.bridge.SLF4JBridgeHandler" } }