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
a66045fa
Commit
a66045fa
authored
Mar 29, 2016
by
Stephane Nicoll
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Polish contribution
Closes gh-5521
parent
c86284ce
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
35 additions
and
9 deletions
+35
-9
spring-boot-features.adoc
spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc
+5
-2
SpringPropertyAction.java
...gframework/boot/logging/logback/SpringPropertyAction.java
+2
-5
SpringBootJoranConfiguratorTests.java
...oot/logging/logback/SpringBootJoranConfiguratorTests.java
+21
-2
property-default-value.xml
...framework/boot/logging/logback/property-default-value.xml
+6
-0
property.xml
...ces/org/springframework/boot/logging/logback/property.xml
+1
-0
No files found.
spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc
View file @
a66045fa
...
@@ -1351,11 +1351,14 @@ for use within Logback. This can be useful if you want to access values from you
...
@@ -1351,11 +1351,14 @@ for use within Logback. This can be useful if you want to access values from you
`application.properties` file in your logback configuration. The tag works in a similar
`application.properties` file in your logback configuration. The tag works in a similar
way to Logback's standard `<property>` tag, but rather than specifying a direct `value`
way to Logback's standard `<property>` tag, but rather than specifying a direct `value`
you specify the `source` of the property (from the `Environment`). You can use the `scope`
you specify the `source` of the property (from the `Environment`). You can use the `scope`
attribute if you need to store the property somewhere other than in `local` scope.
attribute if you need to store the property somewhere other than in `local` scope. If
you need a fallback value in case the property is not set in the `Environment`, you can
use the `defaultValue` attribute.
[source,xml,indent=0]
[source,xml,indent=0]
----
----
<springProperty scope="context" name="fluentHost" source="myapp.fluentd.host"/>
<springProperty scope="context" name="fluentHost" source="myapp.fluentd.host"
defaultValue="localhost"/>
<appender name="FLUENT" class="ch.qos.logback.more.appenders.DataFluentAppender">
<appender name="FLUENT" class="ch.qos.logback.more.appenders.DataFluentAppender">
<remoteHost>${fluentHost}</remoteHost>
<remoteHost>${fluentHost}</remoteHost>
...
...
...
...
spring-boot/src/main/java/org/springframework/boot/logging/logback/SpringPropertyAction.java
View file @
a66045fa
...
@@ -62,9 +62,6 @@ class SpringPropertyAction extends Action {
...
@@ -62,9 +62,6 @@ class SpringPropertyAction extends Action {
private
String
getValue
(
String
source
,
String
defaultValue
)
{
private
String
getValue
(
String
source
,
String
defaultValue
)
{
if
(
this
.
environment
==
null
)
{
if
(
this
.
environment
==
null
)
{
addWarn
(
"No Spring Environment available to resolve "
+
source
);
addWarn
(
"No Spring Environment available to resolve "
+
source
);
return
null
;
}
if
(
source
==
null
)
{
return
defaultValue
;
return
defaultValue
;
}
}
String
value
=
this
.
environment
.
getProperty
(
source
);
String
value
=
this
.
environment
.
getProperty
(
source
);
...
@@ -76,9 +73,9 @@ class SpringPropertyAction extends Action {
...
@@ -76,9 +73,9 @@ class SpringPropertyAction extends Action {
String
prefix
=
source
.
substring
(
0
,
lastDot
+
1
);
String
prefix
=
source
.
substring
(
0
,
lastDot
+
1
);
RelaxedPropertyResolver
resolver
=
new
RelaxedPropertyResolver
(
RelaxedPropertyResolver
resolver
=
new
RelaxedPropertyResolver
(
this
.
environment
,
prefix
);
this
.
environment
,
prefix
);
return
resolver
.
getProperty
(
source
.
substring
(
lastDot
+
1
));
return
resolver
.
getProperty
(
source
.
substring
(
lastDot
+
1
)
,
defaultValue
);
}
}
return
null
;
return
defaultValue
;
}
}
@Override
@Override
...
...
spring-boot/src/test/java/org/springframework/boot/logging/logback/SpringBootJoranConfiguratorTests.java
View file @
a66045fa
...
@@ -41,6 +41,7 @@ import static org.hamcrest.Matchers.not;
...
@@ -41,6 +41,7 @@ import static org.hamcrest.Matchers.not;
*
*
* @author Phillip Webb
* @author Phillip Webb
* @author Eddú Meléndez
* @author Eddú Meléndez
* @author Stephane Nicoll
*/
*/
public
class
SpringBootJoranConfiguratorTests
{
public
class
SpringBootJoranConfiguratorTests
{
...
@@ -140,10 +141,28 @@ public class SpringBootJoranConfiguratorTests {
...
@@ -140,10 +141,28 @@ public class SpringBootJoranConfiguratorTests {
assertThat
(
this
.
context
.
getProperty
(
"MINE"
)).
isEqualTo
(
"test"
);
assertThat
(
this
.
context
.
getProperty
(
"MINE"
)).
isEqualTo
(
"test"
);
}
}
@Test
public
void
springPropertyNoValue
()
throws
Exception
{
initialize
(
"property.xml"
);
assertThat
(
this
.
context
.
getProperty
(
"SIMPLE"
)).
isNull
();
}
@Test
public
void
relaxedSpringPropertyNoValue
()
throws
Exception
{
initialize
(
"property.xml"
);
assertThat
(
this
.
context
.
getProperty
(
"MINE"
)).
isNull
();
}
@Test
@Test
public
void
springPropertyWithDefaultValue
()
throws
Exception
{
public
void
springPropertyWithDefaultValue
()
throws
Exception
{
initialize
(
"property-defaultValue.xml"
);
initialize
(
"property-default-value.xml"
);
assertThat
(
this
.
context
.
getProperty
(
"MINE"
)).
isEqualTo
(
"foo"
);
assertThat
(
this
.
context
.
getProperty
(
"SIMPLE"
)).
isEqualTo
(
"foo"
);
}
@Test
public
void
relaxedSpringPropertyWithDefaultValue
()
throws
Exception
{
initialize
(
"property-default-value.xml"
);
assertThat
(
this
.
context
.
getProperty
(
"MINE"
)).
isEqualTo
(
"bar"
);
}
}
private
void
doTestNestedProfile
(
boolean
expected
,
String
...
profiles
)
private
void
doTestNestedProfile
(
boolean
expected
,
String
...
profiles
)
...
...
spring-boot/src/test/resources/org/springframework/boot/logging/logback/property-default
V
alue.xml
→
spring-boot/src/test/resources/org/springframework/boot/logging/logback/property-default
-v
alue.xml
View file @
a66045fa
<?xml version="1.0" encoding="UTF-8"?>
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<configuration>
<include
resource=
"org/springframework/boot/logging/logback/base.xml"
/>
<include
resource=
"org/springframework/boot/logging/logback/base.xml"
/>
<springProperty
scope=
"context"
name=
"MINE"
defaultValue=
"foo"
/>
<springProperty
scope=
"context"
name=
"SIMPLE"
source=
"testpropertyfoobar"
defaultValue=
"foo"
/>
<springProperty
scope=
"context"
name=
"MINE"
source=
"my.example-property"
defaultValue=
"bar"
/>
</configuration>
</configuration>
spring-boot/src/test/resources/org/springframework/boot/logging/logback/property.xml
View file @
a66045fa
<?xml version="1.0" encoding="UTF-8"?>
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<configuration>
<include
resource=
"org/springframework/boot/logging/logback/base.xml"
/>
<include
resource=
"org/springframework/boot/logging/logback/base.xml"
/>
<springProperty
scope=
"context"
name=
"SIMPLE"
source=
"testpropertyfoobar"
/>
<springProperty
scope=
"context"
name=
"MINE"
source=
"my.example-property"
/>
<springProperty
scope=
"context"
name=
"MINE"
source=
"my.example-property"
/>
</configuration>
</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