Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Expand All @@ -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"
}
}

Expand Down Expand Up @@ -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"
}
}

Expand Down
Loading