Add methods for temporarily changing logging configuration for the duration of a Closure/Action


(Luke Daley) #1

I’d like to add the following method to javadoc:org.gradle.api.logging.LoggingManager

Object withLevel(LogLevel newLevel, Closure action) {
  LogLevel oldLogLevel = getLevel()
  level = [newLevel, oldLogLevel].min()
  try {
    action()
  } finally {
    if (oldLogLevel) {
      level = oldLogLevel
    }
  }
}

This would probably mean adding ‘Action’ overloads and equivalents for other methods on ‘LoggingManager’.

This is most useful for configuring the verbosity of logging code you don’t control, for part of a task’s execution.