Commit 838e0ef3 authored by Andy Wilkinson's avatar Andy Wilkinson

Polish contribution

- Extract the logic that coerces the string into a LogLevel into a
  separate method.
- Add a test that verifies that false is mapped to LogLevel.OFF

Closes gh-3628
parent cbd37b58
...@@ -246,18 +246,20 @@ public class LoggingApplicationListener implements SmartApplicationListener { ...@@ -246,18 +246,20 @@ public class LoggingApplicationListener implements SmartApplicationListener {
name = null; name = null;
} }
level = environment.resolvePlaceholders(level); level = environment.resolvePlaceholders(level);
if (Boolean.toString(false).equalsIgnoreCase(level)) { system.setLogLevel(name, coerceLogLevel(level));
system.setLogLevel(name, LogLevel.OFF);
}
else {
system.setLogLevel(name, LogLevel.valueOf(level.toUpperCase()));
}
} }
catch (RuntimeException ex) { catch (RuntimeException ex) {
this.logger.error("Cannot set level: " + level + " for '" + name + "'"); this.logger.error("Cannot set level: " + level + " for '" + name + "'");
} }
} }
private LogLevel coerceLogLevel(String level) {
if ("false".equalsIgnoreCase(level)) {
return LogLevel.OFF;
}
return LogLevel.valueOf(level.toUpperCase());
}
public void setOrder(int order) { public void setOrder(int order) {
this.order = order; this.order = order;
} }
......
...@@ -258,6 +258,18 @@ public class LoggingApplicationListenerTests { ...@@ -258,6 +258,18 @@ public class LoggingApplicationListenerTests {
assertThat(this.outputCapture.toString(), not(containsString("testatfatal"))); assertThat(this.outputCapture.toString(), not(containsString("testatfatal")));
} }
@Test
public void parseLevelsMapsFalseToOff() throws Exception {
EnvironmentTestUtils.addEnvironment(this.context,
"logging.level.org.springframework.boot=false");
this.initializer.initialize(this.context.getEnvironment(),
this.context.getClassLoader());
this.logger.debug("testatdebug");
this.logger.fatal("testatfatal");
assertThat(this.outputCapture.toString(), not(containsString("testatdebug")));
assertThat(this.outputCapture.toString(), not(containsString("testatfatal")));
}
@Test @Test
public void parseArgsDisabled() throws Exception { public void parseArgsDisabled() throws Exception {
this.initializer.setParseArgs(false); this.initializer.setParseArgs(false);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment