Skip to content

Commit cbd37b5

Browse files
shanman190wilkinsona
authored andcommitted
Make it easier to use YAML configuration to turn off a logger
A level named off is used to disable logging for a particular logger. YAML interprets off as false, leading to a failed attempt to get the LogLevel for FALSE. A workaround is to quote the level, i.e. use "off" rather than off. This commit updates LoggingApplicationListener to coerce the string false back to the level off. Closes gh-3631 See gh-3628
1 parent d241171 commit cbd37b5

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

spring-boot/src/main/java/org/springframework/boot/logging/LoggingApplicationListener.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,12 @@ private void setLogLevel(LoggingSystem system, Environment environment, String n
246246
name = null;
247247
}
248248
level = environment.resolvePlaceholders(level);
249-
system.setLogLevel(name, LogLevel.valueOf(level.toUpperCase()));
249+
if (Boolean.toString(false).equalsIgnoreCase(level)) {
250+
system.setLogLevel(name, LogLevel.OFF);
251+
}
252+
else {
253+
system.setLogLevel(name, LogLevel.valueOf(level.toUpperCase()));
254+
}
250255
}
251256
catch (RuntimeException ex) {
252257
this.logger.error("Cannot set level: " + level + " for '" + name + "'");

0 commit comments

Comments
 (0)