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..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,30 +498,17 @@ abstract class JULBackend extends LogInjectionSmokeTest { false } - def setupSpec() { + 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" - } - } - - def cleanupSpec() { - propertiesFile?.delete() - } - - List additionalArguments() { - return ["-Djava.util.logging.config.file=${propertiesFile.absolutePath}" as String] + 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" } } @@ -711,29 +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 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() { - return ["-Djava.util.logging.config.file=${propertiesFile.absolutePath}" as String] + protected void writeJulProperties(PrintWriter out) { + out.println "handlers=org.slf4j.bridge.SLF4JBridgeHandler" } }