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
This commit is contained in:
shanman190 2015-07-30 16:37:35 -05:00 committed by Andy Wilkinson
parent d241171fff
commit cbd37b583f

View File

@ -246,7 +246,12 @@ public class LoggingApplicationListener implements SmartApplicationListener {
name = null;
}
level = environment.resolvePlaceholders(level);
system.setLogLevel(name, LogLevel.valueOf(level.toUpperCase()));
if (Boolean.toString(false).equalsIgnoreCase(level)) {
system.setLogLevel(name, LogLevel.OFF);
}
else {
system.setLogLevel(name, LogLevel.valueOf(level.toUpperCase()));
}
}
catch (RuntimeException ex) {
this.logger.error("Cannot set level: " + level + " for '" + name + "'");