diff --git a/spring-boot/src/main/java/org/springframework/boot/logging/logback/SpringProfileAction.java b/spring-boot/src/main/java/org/springframework/boot/logging/logback/SpringProfileAction.java index 9233ef7550b..8c9ce1318a3 100644 --- a/spring-boot/src/main/java/org/springframework/boot/logging/logback/SpringProfileAction.java +++ b/spring-boot/src/main/java/org/springframework/boot/logging/logback/SpringProfileAction.java @@ -21,6 +21,7 @@ import java.util.List; import org.springframework.core.env.Environment; import org.springframework.util.Assert; +import org.springframework.util.StringUtils; import org.xml.sax.Attributes; import ch.qos.logback.core.joran.action.Action; @@ -36,6 +37,7 @@ import ch.qos.logback.core.util.OptionHelper; * logback configuration to only be enabled when a specific profile is active. * * @author Phillip Webb + * @author Eddú Meléndez */ class SpringProfileAction extends Action implements InPlayListener { @@ -65,11 +67,14 @@ class SpringProfileAction extends Action implements InPlayListener { } private boolean acceptsProfiles(InterpretationContext ic, Attributes attributes) { - String profileName = attributes.getValue(NAME_ATTRIBUTE); - if (!OptionHelper.isEmpty(profileName)) { - OptionHelper.substVars(profileName, ic, this.context); + String[] profileNames = StringUtils.commaDelimitedListToStringArray(attributes + .getValue(NAME_ATTRIBUTE)); + if (profileNames.length != 0) { + for (String profileName : profileNames) { + OptionHelper.substVars(profileName, ic, this.context); + } return this.environment != null - && this.environment.acceptsProfiles(profileName); + && this.environment.acceptsProfiles(profileNames); } return false; } diff --git a/spring-boot/src/test/java/org/springframework/boot/logging/logback/SpringBootJoranConfiguratorTests.java b/spring-boot/src/test/java/org/springframework/boot/logging/logback/SpringBootJoranConfiguratorTests.java index fc87e542d1c..61057dbd77b 100644 --- a/spring-boot/src/test/java/org/springframework/boot/logging/logback/SpringBootJoranConfiguratorTests.java +++ b/spring-boot/src/test/java/org/springframework/boot/logging/logback/SpringBootJoranConfiguratorTests.java @@ -40,6 +40,7 @@ import static org.junit.Assert.assertThat; * Tests for {@link SpringBootJoranConfigurator}. * * @author Phillip Webb + * @author Eddú Meléndez */ public class SpringBootJoranConfiguratorTests { @@ -79,6 +80,22 @@ public class SpringBootJoranConfiguratorTests { this.out.expect(containsString("Hello")); } + @Test + public void multipleNamesFirstProfileActive() throws Exception { + this.environment.setActiveProfiles("production"); + initialize("multi-profile-names.xml"); + this.logger.trace("Hello"); + this.out.expect(containsString("Hello")); + } + + @Test + public void multipleNamesSecondProfileActive() throws Exception { + this.environment.setActiveProfiles("test"); + initialize("multi-profile-names.xml"); + this.logger.trace("Hello"); + this.out.expect(containsString("Hello")); + } + @Test public void profileNotActive() throws Exception { initialize("production-profile.xml"); diff --git a/spring-boot/src/test/resources/org/springframework/boot/logging/logback/multi-profile-names.xml b/spring-boot/src/test/resources/org/springframework/boot/logging/logback/multi-profile-names.xml new file mode 100644 index 00000000000..55ccd71ee5d --- /dev/null +++ b/spring-boot/src/test/resources/org/springframework/boot/logging/logback/multi-profile-names.xml @@ -0,0 +1,7 @@ + + + + + + +