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
a26ae0a3
Commit
a26ae0a3
authored
Jan 28, 2014
by
Dave Syer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Re-initialize logging if Environment changed settings
Fixes gh-273
parent
5c6690f7
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
4 deletions
+24
-4
LoggingApplicationListener.java
...ork/boot/context/listener/LoggingApplicationListener.java
+6
-0
LoggingApplicationListenerTests.java
...oot/context/listener/LoggingApplicationListenerTests.java
+18
-4
No files found.
spring-boot/src/main/java/org/springframework/boot/context/listener/LoggingApplicationListener.java
View file @
a26ae0a3
...
...
@@ -153,16 +153,22 @@ public class LoggingApplicationListener implements SmartApplicationListener {
}
}
boolean
environmentChanged
=
false
;
for
(
Map
.
Entry
<
String
,
String
>
mapping
:
ENVIRONMENT_SYSTEM_PROPERTY_MAPPING
.
entrySet
())
{
if
(
environment
.
containsProperty
(
mapping
.
getKey
()))
{
System
.
setProperty
(
mapping
.
getValue
(),
environment
.
getProperty
(
mapping
.
getKey
()));
environmentChanged
=
true
;
}
}
LoggingSystem
system
=
LoggingSystem
.
get
(
classLoader
);
if
(
environmentChanged
)
{
// Re-initialize the defaults in case the Environment changed
system
.
beforeInitialize
();
}
// User specified configuration
if
(
environment
.
containsProperty
(
"logging.config"
))
{
String
value
=
environment
.
getProperty
(
"logging.config"
);
...
...
spring-boot/src/test/java/org/springframework/boot/context/listener/LoggingApplicationListenerTests.java
View file @
a26ae0a3
...
...
@@ -16,6 +16,7 @@
package
org
.
springframework
.
boot
.
context
.
listener
;
import
java.io.File
;
import
java.io.IOException
;
import
java.util.logging.LogManager
;
...
...
@@ -71,6 +72,7 @@ public class LoggingApplicationListenerTests {
JavaLoggingSystem
.
class
.
getResourceAsStream
(
"logging.properties"
));
this
.
initializer
.
onApplicationEvent
(
new
SpringApplicationStartEvent
(
new
SpringApplication
(),
NO_ARGS
));
new
File
(
"target/foo.log"
).
delete
();
}
@After
...
...
@@ -119,25 +121,37 @@ public class LoggingApplicationListenerTests {
public
void
testAddLogFileProperty
()
{
EnvironmentTestUtils
.
addEnvironment
(
this
.
context
,
"logging.config: classpath:logback-nondefault.xml"
,
"logging.file: foo.log"
);
"logging.file:
target/
foo.log"
);
this
.
initializer
.
initialize
(
this
.
context
.
getEnvironment
(),
this
.
context
.
getClassLoader
());
Log
logger
=
LogFactory
.
getLog
(
LoggingApplicationListenerTests
.
class
);
logger
.
info
(
"Hello world"
);
String
output
=
this
.
outputCapture
.
toString
().
trim
();
assertTrue
(
"Wrong output:\n"
+
output
,
output
.
startsWith
(
"foo.log"
));
assertTrue
(
"Wrong output:\n"
+
output
,
output
.
startsWith
(
"target/foo.log"
));
}
@Test
public
void
testAddLogFilePropertyWithDefault
()
{
assertFalse
(
new
File
(
"target/foo.log"
).
exists
());
EnvironmentTestUtils
.
addEnvironment
(
this
.
context
,
"logging.file: target/foo.log"
);
this
.
initializer
.
initialize
(
this
.
context
.
getEnvironment
(),
this
.
context
.
getClassLoader
());
Log
logger
=
LogFactory
.
getLog
(
LoggingApplicationListenerTests
.
class
);
logger
.
info
(
"Hello world"
);
assertTrue
(
new
File
(
"target/foo.log"
).
exists
());
}
@Test
public
void
testAddLogPathProperty
()
{
EnvironmentTestUtils
.
addEnvironment
(
this
.
context
,
"logging.config: classpath:logback-nondefault.xml"
,
"logging.path: foo/"
);
"logging.config: classpath:logback-nondefault.xml"
,
"logging.path: target/foo/"
);
this
.
initializer
.
initialize
(
this
.
context
.
getEnvironment
(),
this
.
context
.
getClassLoader
());
Log
logger
=
LogFactory
.
getLog
(
LoggingApplicationListenerTests
.
class
);
logger
.
info
(
"Hello world"
);
String
output
=
this
.
outputCapture
.
toString
().
trim
();
assertTrue
(
"Wrong output:\n"
+
output
,
output
.
startsWith
(
"foo/spring.log"
));
assertTrue
(
"Wrong output:\n"
+
output
,
output
.
startsWith
(
"
target/
foo/spring.log"
));
}
@Test
...
...
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