How to change log level between lifecycles

I have java/groovy code that is built under buildSrc that I want as quiet as possible as it’s not the focus of the build and rarely changes. Once that’s built I want to set the log level to INFO to be more verbose for the rest of the build

I’ve tried to set the level in the main buildscript block:

buildscript {
 logging.setLevel(LogLevel.ERROR)
}

which has no effect on the buildSrc build

To increase the level post buildSrc, I tried this.

task configured {
  logging.setLevel(LogLevel.DEBUG)
}

All of which have no effect on the actual logging.

The only way I can change what’s logged is by using the -q, -i, -d args, which affect it globally.

What is the right way to step logging verbosity up/down at different lifecycle phases?

‘buildSrc’ and ‘buildscript’ are unrelated. What I’d try to do is to set a log level for all tasks in ‘buildSrc’ (via ‘buildSrc/build.gradle’). From what I remember, there is an open ticket though that ‘Task.logging.setLogLevel()’ isn’t working. I’m not sure if there is another way. Since ‘buildSrc’ is being built strictly before the main build, there might be a way to temporarily change the logging level, perhaps via ‘gradle.startParameter.setLogLevel()’.

So it appears that the logging.setLevel(LogLevel) is working in that it does set the value, but the logger.* methods are not using it.

logging.setLevel(LogLevel.DEBUG)
logger.error("logger=${project.logging.getLevel()}")
logger.debug("debug")
logger.info("info")
logger.error("error")
logger.lifecycle("lifecycle")
logger.quiet("quiet")
logger.warn("warn")

prints:

logger=DEBUG
error
lifecycle
quiet
warn

I would have expected to see the debug and info messages as well.

In case I’m going about this completely the wrong way, my goal is to suppress these messages, always, regardless of what -q/i/d arg was passed to gradle:

:buildSrc:compileJava
Executing task ':compileJava' (up-to-date check took 0.045 secs) due to:
  Input file /opt/jetty/.gradle/caches/artifacts-26/filestore/commons-beanutils/commons-beanutils/1.8.0/jar/c651d5103c649c12b20d53731643e5fffceb536/commons-beanutils-1.8.0.jar has been added.
  .....
  :buildSrc:check
Skipping task ':check' as it has no actions.
:buildSrc:check UP-TO-DATE
:check (Thread[Daemon Thread 7,5,main]) completed. Took 0.0 secs.
:build (Thread[Daemon Thread 7,5,main]) started.
:buildSrc:build
Skipping task ':build' as it has no actions.
:build (Thread[Daemon Thread 7,5,main]) completed. Took 0.001 secs.
Stopping 1 Gradle compiler daemon(s).
Process 'Gradle Worker 1' finished with exit value 0 (state: SUCCEEDED)
Stopped 1 Gradle compiler daemon(s).
================================================ Finished building buildSrc

And then resume logging with whatever was specified on the command line.

I assumed that monkeying with the logging instance level would be the way to go.