Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
S
spring-boot
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
DEMO
spring-boot
Commits
b4584e6a
Commit
b4584e6a
authored
Jun 18, 2018
by
Stephane Nicoll
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Support profile expression in Logback's <springProfile>
Closes gh-13496
parent
a89b2ae4
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
42 additions
and
6 deletions
+42
-6
spring-boot-features.adoc
...ing-boot-docs/src/main/asciidoc/spring-boot-features.adoc
+7
-3
SpringProfileAction.java
...ngframework/boot/logging/logback/SpringProfileAction.java
+3
-2
SpringBootJoranConfiguratorTests.java
...oot/logging/logback/SpringBootJoranConfiguratorTests.java
+25
-1
profile-expression.xml
...ringframework/boot/logging/logback/profile-expression.xml
+7
-0
No files found.
spring-boot-project/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc
View file @
b4584e6a
...
...
@@ -1820,8 +1820,12 @@ ERROR in ch.qos.logback.core.joran.spi.Interpreter@4:71 - no applicable action f
The `<springProfile>` tag lets you optionally include or exclude sections of
configuration based on the active Spring profiles. Profile sections are supported
anywhere within the `<configuration>` 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 `<springProfile> 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:
<!-- configuration to be enabled when the "staging" profile is active -->
</springProfile>
<springProfile name="dev
,
staging">
<springProfile name="dev
|
staging">
<!-- configuration to be enabled when the "dev" or "staging" profiles are active -->
</springProfile>
...
...
spring-boot-project/spring-boot/src/main/java/org/springframework/boot/logging/logback/SpringProfileAction.java
View file @
b4584e6a
/*
* Copyright 2012-201
7
the original author or authors.
* Copyright 2012-201
8
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
;
}
...
...
spring-boot-project/spring-boot/src/test/java/org/springframework/boot/logging/logback/SpringBootJoranConfiguratorTests.java
View file @
b4584e6a
/*
* Copyright 2012-201
7
the original author or authors.
* Copyright 2012-201
8
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"
);
...
...
spring-boot-project/spring-boot/src/test/resources/org/springframework/boot/logging/logback/profile-expression.xml
0 → 100644
View file @
b4584e6a
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<include
resource=
"org/springframework/boot/logging/logback/base.xml"
/>
<springProfile
name=
"production | test"
>
<logger
name=
"org.springframework.boot.logging.logback"
level=
"TRACE"
/>
</springProfile>
</configuration>
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment