Skip to content

Commit 7eccbc4

Browse files
author
Dave Syer
committed
Make LoggingRebinder case insensitive
Partly to account for the fact that Sprng Boot publishes config meta data with lower case values (don't ask).
1 parent bfd25e1 commit 7eccbc4

File tree

2 files changed

+29
-14
lines changed

2 files changed

+29
-14
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@
3535
* @author Dave Syer
3636
*
3737
*/
38-
public class LoggingRebinder implements ApplicationListener<EnvironmentChangeEvent>,
39-
EnvironmentAware {
38+
public class LoggingRebinder
39+
implements ApplicationListener<EnvironmentChangeEvent>, EnvironmentAware {
4040

4141
private final Log logger = LogFactory.getLog(getClass());
4242

@@ -71,7 +71,7 @@ private void setLogLevel(LoggingSystem system, Environment environment, String n
7171
name = null;
7272
}
7373
level = environment.resolvePlaceholders(level);
74-
system.setLogLevel(name, LogLevel.valueOf(level));
74+
system.setLogLevel(name, LogLevel.valueOf(level.toUpperCase()));
7575
}
7676
catch (RuntimeException ex) {
7777
this.logger.error("Cannot set level: " + level + " for '" + name + "'");

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

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,6 @@
1515
*/
1616
package org.springframework.cloud.logging;
1717

18-
import static org.junit.Assert.assertFalse;
19-
import static org.junit.Assert.assertTrue;
20-
2118
import java.util.Collections;
2219

2320
import org.junit.After;
@@ -27,8 +24,11 @@
2724
import org.springframework.boot.logging.LogLevel;
2825
import org.springframework.boot.logging.LoggingSystem;
2926
import org.springframework.boot.test.EnvironmentTestUtils;
30-
import org.springframework.core.env.StandardEnvironment;
3127
import org.springframework.cloud.context.environment.EnvironmentChangeEvent;
28+
import org.springframework.core.env.StandardEnvironment;
29+
30+
import static org.junit.Assert.assertFalse;
31+
import static org.junit.Assert.assertTrue;
3232

3333
/**
3434
* @author Dave Syer
@@ -38,20 +38,35 @@ public class LoggingRebinderTests {
3838

3939
private LoggingRebinder rebinder = new LoggingRebinder();
4040
private Logger logger = LoggerFactory.getLogger("org.springframework.web");
41-
41+
4242
@After
4343
public void reset() {
44-
LoggingSystem.get(getClass().getClassLoader()).setLogLevel("org.springframework.web", LogLevel.INFO);
44+
LoggingSystem.get(getClass().getClassLoader())
45+
.setLogLevel("org.springframework.web", LogLevel.INFO);
4546
}
4647

4748
@Test
4849
public void logLevelsChanged() {
49-
assertFalse(logger.isTraceEnabled());
50+
assertFalse(this.logger.isTraceEnabled());
51+
StandardEnvironment environment = new StandardEnvironment();
52+
EnvironmentTestUtils.addEnvironment(environment,
53+
"logging.level.org.springframework.web=TRACE");
54+
this.rebinder.setEnvironment(environment);
55+
this.rebinder.onApplicationEvent(new EnvironmentChangeEvent(
56+
Collections.singleton("logging.level.org.springframework.web")));
57+
assertTrue(this.logger.isTraceEnabled());
58+
}
59+
60+
@Test
61+
public void logLevelsLowerCase() {
62+
assertFalse(this.logger.isTraceEnabled());
5063
StandardEnvironment environment = new StandardEnvironment();
51-
EnvironmentTestUtils.addEnvironment(environment, "logging.level.org.springframework.web=TRACE");
52-
rebinder.setEnvironment(environment);
53-
rebinder.onApplicationEvent(new EnvironmentChangeEvent(Collections.singleton("logging.level.org.springframework.web")));
54-
assertTrue(logger.isTraceEnabled());
64+
EnvironmentTestUtils.addEnvironment(environment,
65+
"logging.level.org.springframework.web=trace");
66+
this.rebinder.setEnvironment(environment);
67+
this.rebinder.onApplicationEvent(new EnvironmentChangeEvent(
68+
Collections.singleton("logging.level.org.springframework.web")));
69+
assertTrue(this.logger.isTraceEnabled());
5570
}
5671

5772
}

0 commit comments

Comments
 (0)