From 3b2fb305c856d834ea45a344c0ef1da0919d7a6e Mon Sep 17 00:00:00 2001 From: Dave Syer Date: Thu, 9 Oct 2014 19:13:41 +0100 Subject: [PATCH] Add placeholder support to LoggingApplicationListener When logging.level.* is set in external configuration they can now contain placeholders. Fixes gh-1680 --- .../boot/logging/LoggingApplicationListener.java | 2 +- .../logging/LoggingApplicationListenerTests.java | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/spring-boot/src/main/java/org/springframework/boot/logging/LoggingApplicationListener.java b/spring-boot/src/main/java/org/springframework/boot/logging/LoggingApplicationListener.java index ba35a9b385..aaa1299083 100644 --- a/spring-boot/src/main/java/org/springframework/boot/logging/LoggingApplicationListener.java +++ b/spring-boot/src/main/java/org/springframework/boot/logging/LoggingApplicationListener.java @@ -224,7 +224,7 @@ public class LoggingApplicationListener implements SmartApplicationListener { for (Entry 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; } diff --git a/spring-boot/src/test/java/org/springframework/boot/logging/LoggingApplicationListenerTests.java b/spring-boot/src/test/java/org/springframework/boot/logging/LoggingApplicationListenerTests.java index 3735f18d13..eb871fa1dc 100644 --- a/spring-boot/src/test/java/org/springframework/boot/logging/LoggingApplicationListenerTests.java +++ b/spring-boot/src/test/java/org/springframework/boot/logging/LoggingApplicationListenerTests.java @@ -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,