diff --git a/spring-cloud-context/src/main/java/org/springframework/cloud/logging/LoggingRebinder.java b/spring-cloud-context/src/main/java/org/springframework/cloud/logging/LoggingRebinder.java index a1f8a77d..132f1afa 100644 --- a/spring-cloud-context/src/main/java/org/springframework/cloud/logging/LoggingRebinder.java +++ b/spring-cloud-context/src/main/java/org/springframework/cloud/logging/LoggingRebinder.java @@ -17,6 +17,7 @@ package org.springframework.cloud.logging; import java.util.Collections; +import java.util.Locale; import java.util.Map; import java.util.Map.Entry; @@ -37,6 +38,7 @@ import org.springframework.core.env.Environment; * changed. * * @author Dave Syer + * @author Olga Maciaszek-Sharma * */ public class LoggingRebinder @@ -79,11 +81,19 @@ public class LoggingRebinder name = null; } level = environment.resolvePlaceholders(level); - system.setLogLevel(name, LogLevel.valueOf(level.toUpperCase())); + system.setLogLevel(name, resolveLogLevel(level)); } catch (RuntimeException ex) { this.logger.error("Cannot set level: " + level + " for '" + name + "'"); } } + private LogLevel resolveLogLevel(String level) { + String trimmedLevel = level.trim(); + if ("false".equalsIgnoreCase(trimmedLevel)) { + return LogLevel.OFF; + } + return LogLevel.valueOf(trimmedLevel.toUpperCase(Locale.ENGLISH)); + } + } diff --git a/spring-cloud-context/src/test/java/org/springframework/cloud/logging/LoggingRebinderTests.java b/spring-cloud-context/src/test/java/org/springframework/cloud/logging/LoggingRebinderTests.java index 9a626783..4b97c0bc 100644 --- a/spring-cloud-context/src/test/java/org/springframework/cloud/logging/LoggingRebinderTests.java +++ b/spring-cloud-context/src/test/java/org/springframework/cloud/logging/LoggingRebinderTests.java @@ -18,6 +18,7 @@ package org.springframework.cloud.logging; import java.util.Collections; +import ch.qos.logback.classic.Level; import org.junit.After; import org.junit.Test; import org.slf4j.Logger; @@ -33,6 +34,7 @@ import static org.assertj.core.api.BDDAssertions.then; /** * @author Dave Syer + * @author Olga Maciaszek-Sharma * */ public class LoggingRebinderTests { @@ -71,4 +73,17 @@ public class LoggingRebinderTests { then(this.logger.isTraceEnabled()).isTrue(); } + @Test + public void logLevelFalseResolvedToOff() { + ch.qos.logback.classic.Logger logger = (ch.qos.logback.classic.Logger) LoggerFactory + .getLogger("org.springframework.cloud"); + StandardEnvironment environment = new StandardEnvironment(); + TestPropertyValues.of("logging.level.org.springframework.cloud=false") + .applyTo(environment); + rebinder.setEnvironment(environment); + rebinder.onApplicationEvent(new EnvironmentChangeEvent(environment, + Collections.singleton("logging.level.org.springframework.cloud"))); + then(Level.OFF).isEqualTo((logger.getLevel())); + } + }