Skip to content

Commit acfb07b

Browse files
committed
Merge branch 'gh-3628' into 1.2.x
2 parents d241171 + 838e0ef commit acfb07b

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,13 +246,20 @@ 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+
system.setLogLevel(name, coerceLogLevel(level));
250250
}
251251
catch (RuntimeException ex) {
252252
this.logger.error("Cannot set level: " + level + " for '" + name + "'");
253253
}
254254
}
255255

256+
private LogLevel coerceLogLevel(String level) {
257+
if ("false".equalsIgnoreCase(level)) {
258+
return LogLevel.OFF;
259+
}
260+
return LogLevel.valueOf(level.toUpperCase());
261+
}
262+
256263
public void setOrder(int order) {
257264
this.order = order;
258265
}

spring-boot/src/test/java/org/springframework/boot/logging/LoggingApplicationListenerTests.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,18 @@ public void parseLevelsNone() throws Exception {
258258
assertThat(this.outputCapture.toString(), not(containsString("testatfatal")));
259259
}
260260

261+
@Test
262+
public void parseLevelsMapsFalseToOff() throws Exception {
263+
EnvironmentTestUtils.addEnvironment(this.context,
264+
"logging.level.org.springframework.boot=false");
265+
this.initializer.initialize(this.context.getEnvironment(),
266+
this.context.getClassLoader());
267+
this.logger.debug("testatdebug");
268+
this.logger.fatal("testatfatal");
269+
assertThat(this.outputCapture.toString(), not(containsString("testatdebug")));
270+
assertThat(this.outputCapture.toString(), not(containsString("testatfatal")));
271+
}
272+
261273
@Test
262274
public void parseArgsDisabled() throws Exception {
263275
this.initializer.setParseArgs(false);

0 commit comments

Comments
 (0)