Add placeholder support to LoggingApplicationListener

When logging.level.* is set in external configuration they can now
contain placeholders.

Fixes gh-1680
This commit is contained in:
Dave Syer
2014-10-09 19:13:41 +01:00
parent 3135c7f8ae
commit 3b2fb305c8
2 changed files with 13 additions and 1 deletions

View File

@@ -224,7 +224,7 @@ public class LoggingApplicationListener implements SmartApplicationListener {
for (Entry<String, Object> entry : levels.entrySet()) {
String name = entry.getKey();
try {
LogLevel level = LogLevel.valueOf(entry.getValue().toString());
LogLevel level = LogLevel.valueOf(environment.resolvePlaceholders(entry.getValue().toString()));
if (name.equalsIgnoreCase("root")) {
name = null;
}

View File

@@ -204,6 +204,18 @@ public class LoggingApplicationListenerTests {
assertThat(this.outputCapture.toString(), containsString("testattrace"));
}
@Test
public void parseLevelsWithPlaceholder() throws Exception {
EnvironmentTestUtils.addEnvironment(this.context, "foo=TRACE",
"logging.level.org.springframework.boot=${foo}");
this.initializer.initialize(this.context.getEnvironment(),
this.context.getClassLoader());
this.logger.debug("testatdebug");
this.logger.trace("testattrace");
assertThat(this.outputCapture.toString(), containsString("testatdebug"));
assertThat(this.outputCapture.toString(), containsString("testattrace"));
}
@Test
public void parseLevelsFails() throws Exception {
EnvironmentTestUtils.addEnvironment(this.context,