Browse Source

Merge branch '2.1.x'

# Conflicts:
#	docs/pom.xml
#	pom.xml
#	spring-cloud-commons-dependencies/pom.xml
#	spring-cloud-commons/pom.xml
#	spring-cloud-context-integration-tests/pom.xml
#	spring-cloud-context/pom.xml
#	spring-cloud-loadbalancer/pom.xml
#	spring-cloud-starter/pom.xml
#	spring-cloud-test-support/pom.xml
pull/583/head
Olga Maciaszek-Sharma 5 years ago
parent
commit
851a41cd89
  1. 12
      spring-cloud-context/src/main/java/org/springframework/cloud/logging/LoggingRebinder.java
  2. 15
      spring-cloud-context/src/test/java/org/springframework/cloud/logging/LoggingRebinderTests.java

12
spring-cloud-context/src/main/java/org/springframework/cloud/logging/LoggingRebinder.java

@ -17,6 +17,7 @@ @@ -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; @@ -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 @@ -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));
}
}

15
spring-cloud-context/src/test/java/org/springframework/cloud/logging/LoggingRebinderTests.java

@ -18,6 +18,7 @@ package org.springframework.cloud.logging; @@ -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; @@ -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 { @@ -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()));
}
}

Loading…
Cancel
Save