diff --git a/spring-boot-project/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc b/spring-boot-project/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc index e6be4dd5964..49454de7b6e 100644 --- a/spring-boot-project/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc +++ b/spring-boot-project/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc @@ -1820,8 +1820,12 @@ ERROR in ch.qos.logback.core.joran.spi.Interpreter@4:71 - no applicable action f The `` tag lets you optionally include or exclude sections of configuration based on the active Spring profiles. Profile sections are supported anywhere within the `` element. Use the `name` attribute to specify which -profile accepts the configuration. Multiple profiles can be specified with a -comma-separated list. The following listing shows three sample profiles: +profile accepts the configuration. The ` tag can contains a simple profile +name (for example `staging`) or a profile expression. A profile expression allows for more +complicated profile logic to be expressed, for example +`production & (eu-central | eu-west)`. Check the +{spring-reference}core.html#beans-definition-profiles-java[reference guide] for more +details. The following listing shows three sample profiles: [source,xml,indent=0] ---- @@ -1829,7 +1833,7 @@ comma-separated list. The following listing shows three sample profiles: - + diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/logging/logback/SpringProfileAction.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/logging/logback/SpringProfileAction.java index abc6070b0ff..d6b8883d24d 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/logging/logback/SpringProfileAction.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/logging/logback/SpringProfileAction.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2017 the original author or authors. + * Copyright 2012-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -29,6 +29,7 @@ import ch.qos.logback.core.util.OptionHelper; import org.xml.sax.Attributes; import org.springframework.core.env.Environment; +import org.springframework.core.env.Profiles; import org.springframework.util.Assert; import org.springframework.util.StringUtils; @@ -74,7 +75,7 @@ class SpringProfileAction extends Action implements InPlayListener { OptionHelper.substVars(profileName, ic, this.context); } return this.environment != null - && this.environment.acceptsProfiles(profileNames); + && this.environment.acceptsProfiles(Profiles.of(profileNames)); } return false; } diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/logging/logback/SpringBootJoranConfiguratorTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/logging/logback/SpringBootJoranConfiguratorTests.java index eba0279be16..48a0a5f1c9d 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/logging/logback/SpringBootJoranConfiguratorTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/logging/logback/SpringBootJoranConfiguratorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2017 the original author or authors. + * Copyright 2012-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -108,6 +108,30 @@ public class SpringBootJoranConfiguratorTests { this.out.expect(not(containsString("Hello"))); } + @Test + public void profileExpressionMatchFirst() throws Exception { + this.environment.setActiveProfiles("production"); + initialize("profile-expression.xml"); + this.logger.trace("Hello"); + this.out.expect(containsString("Hello")); + } + + @Test + public void profileExpressionMatchSecond() throws Exception { + this.environment.setActiveProfiles("production"); + initialize("profile-expression.xml"); + this.logger.trace("Hello"); + this.out.expect(containsString("Hello")); + } + + @Test + public void profileExpressionNoMatch() throws Exception { + this.environment.setActiveProfiles("development"); + initialize("profile-expression.xml"); + this.logger.trace("Hello"); + this.out.expect(not(containsString("Hello"))); + } + @Test public void profileNestedActiveActive() throws Exception { doTestNestedProfile(true, "outer", "inner"); diff --git a/spring-boot-project/spring-boot/src/test/resources/org/springframework/boot/logging/logback/profile-expression.xml b/spring-boot-project/spring-boot/src/test/resources/org/springframework/boot/logging/logback/profile-expression.xml new file mode 100644 index 00000000000..448bb017a5e --- /dev/null +++ b/spring-boot-project/spring-boot/src/test/resources/org/springframework/boot/logging/logback/profile-expression.xml @@ -0,0 +1,7 @@ + + + + + + +