How can I get the current log level?

My end goal is to be able to do a better job of managing output from my test classes. The current strategy is to pass along the log level passed on the gradle command line to into the jvm arguments as part of the test closure. From there our testng classes will pick up on the system property that was set and dynamically set the log level before the tests run. However, my current problem is that when I try to get the log level back i get a null value. Any thoughts?

Current Setup - Parent Project Build File ------------------------------------------------------------------

      jvmArgs '-Xmx512m', '-XX:MaxPermSize=256m', "-DlogLevel=${logging.level}"

Hello, I need a closer look to check why logging.level returns null here. as a workaround you can use:


regards, René

The workaround above worked. I appreciate it.

Below is the version output for me

------------------------------------------------------------ Gradle 1.0-milestone-8a ------------------------------------------------------------

Gradle build time: Monday, February 20, 2012 4:00:18 PM UTC Groovy: 1.8.4 Ant: Apache Ant™ version 1.8.2 compiled on December 20 2010 Ivy: 2.2.0 JVM: 1.6.0_27 (Sun Microsystems Inc. 20.2-b06) OS: Windows 7 6.1 amd64

The issue is still exists at Gradle 1.6, and w/a still works. Is there a bug to monitor for?

The current behavior is that ‘task.logging.level’ only returns a non-null value if the logging level is explicitly set for that task. (I think there is an open issue that per-task log levels don’t work as intended.) Otherwise, the logging level is inherited from the containing project. ‘gradle.startParameter.logLevel’ is the log level requested on the command line, and may be all you need.

gradle.startParameter.logLevel does work, but it is confusing to have logging.getLevel() return null unless it’s been explicitly set.

1 Like

for me, requsting project.logging.level wihin a task also returns null despite using -q. Using gradle 1.12