Unable to configure java.util.logging with Gradle test task

I’m trying to configure java.util.logging so that I get DEBUG/FINE level output from unit tests and code-under-test. I’m trying to pass java.util.logging.config.file property to the test JVM. I have extracted a test case from my main project and I believe I isolated the issue to Gradle. I’m using Gradle 1.6.

  • In Gradle java.util.logging gets its default configuration. Gradle is passing the JVM property correctly. Here is Gradle code:
test {
    testLogging {
        // set options for log level LIFECYCLE
        events "started","passed","skipped","failed"
        // make the standard output streams visible at console when running tests
        showStandardStreams = true
    }
          // configure java.util.logging for the test JVM(s)
    systemProperty 'java.util.logging.config.file', 'build/resources/test/logging.properties'
  }

And here is a command line that I see with --info output:

/Library/Java/JavaVirtualMachines/jdk1.7.0_17.jdk/Contents/Home/bin/java -Djava.security.manager=jarjar.org.gradle.process.internal.child.BootstrapSecurityManager -Djava.util.logging.config.file=build/resources/test/logging.properties -Dfile.encoding=US-ASCII -ea -cp /Users/DK/.gradle/caches/1.6/workerMain/gradle-worker.jar jarjar.org.gradle.process.internal.launcher.GradleWorkerMain
  • I can run my unit test in Eclipse passing
-Djava.util.logging.config.file=build/resources/test/logging.properties

and get properly configured log output.

  • I can run my test in command line and get proper log output:
java -Djava.util.logging.config.file=build/resources/test/logging.properties -ea -cp build/classes/test:lib/junit-4.11.jar:lib/hamcrest-core-1.3.jar:lib/slf4j-api-1.7.5.jar:lib/slf4j-jdk14-1.7.5.jar org.junit.runner.JUnitCore org.houseofsoft.ArraysTest

Am I missing something here? I read the manual, but could not find what else to do other than

systemProperty 'java.util.logging.config.file'

.

Faced with it too.

We we have this fancy class.

LogManager.getLogManager().reset();

Logger.getLogger("").addHandler(new ConsoleHandler());

So Gradle will not pay attention to your configuration.

Shall I file an issue?

We’re using SLF4J, actually, in my main project, so I’m thinking about switching tests to use SLF4J+logback as a workaround for this issue vs the main app., which is using SLF4J+java.util.logging. Fortunately, with SLF4J it should be easily achievable.

Not sure. We need some attention from Gradle fathers.

I just figured out that issue already exists: http://issues.gradle.org/browse/GRADLE-2524

Thank you! I’ll monitor the bug.