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
e9aa7ca9
Commit
e9aa7ca9
authored
Dec 03, 2015
by
Andy Wilkinson
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch '1.2.x'
parents
03d29fd6
00b668b2
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
65 additions
and
1 deletion
+65
-1
LoggingApplicationListener.java
...ingframework/boot/logging/LoggingApplicationListener.java
+2
-1
LoggingApplicationListenerTests.java
...amework/boot/logging/LoggingApplicationListenerTests.java
+63
-0
No files found.
spring-boot/src/main/java/org/springframework/boot/logging/LoggingApplicationListener.java
View file @
e9aa7ca9
...
@@ -179,7 +179,8 @@ public class LoggingApplicationListener implements GenericApplicationListener {
...
@@ -179,7 +179,8 @@ public class LoggingApplicationListener implements GenericApplicationListener {
else
if
(
event
instanceof
ApplicationPreparedEvent
)
{
else
if
(
event
instanceof
ApplicationPreparedEvent
)
{
onApplicationPreparedEvent
((
ApplicationPreparedEvent
)
event
);
onApplicationPreparedEvent
((
ApplicationPreparedEvent
)
event
);
}
}
else
if
(
event
instanceof
ContextClosedEvent
)
{
else
if
(
event
instanceof
ContextClosedEvent
&&
((
ContextClosedEvent
)
event
)
.
getApplicationContext
().
getParent
()
==
null
)
{
onContextClosedEvent
();
onContextClosedEvent
();
}
}
}
}
...
...
spring-boot/src/test/java/org/springframework/boot/logging/LoggingApplicationListenerTests.java
View file @
e9aa7ca9
...
@@ -42,6 +42,7 @@ import org.springframework.boot.test.EnvironmentTestUtils;
...
@@ -42,6 +42,7 @@ import org.springframework.boot.test.EnvironmentTestUtils;
import
org.springframework.boot.test.OutputCapture
;
import
org.springframework.boot.test.OutputCapture
;
import
org.springframework.context.event.ContextClosedEvent
;
import
org.springframework.context.event.ContextClosedEvent
;
import
org.springframework.context.support.GenericApplicationContext
;
import
org.springframework.context.support.GenericApplicationContext
;
import
org.springframework.test.util.ReflectionTestUtils
;
import
static
org
.
hamcrest
.
Matchers
.
containsString
;
import
static
org
.
hamcrest
.
Matchers
.
containsString
;
import
static
org
.
hamcrest
.
Matchers
.
is
;
import
static
org
.
hamcrest
.
Matchers
.
is
;
...
@@ -97,6 +98,7 @@ public class LoggingApplicationListenerTests {
...
@@ -97,6 +98,7 @@ public class LoggingApplicationListenerTests {
System
.
clearProperty
(
"LOG_PATH"
);
System
.
clearProperty
(
"LOG_PATH"
);
System
.
clearProperty
(
"PID"
);
System
.
clearProperty
(
"PID"
);
System
.
clearProperty
(
"LOG_EXCEPTION_CONVERSION_WORD"
);
System
.
clearProperty
(
"LOG_EXCEPTION_CONVERSION_WORD"
);
System
.
clearProperty
(
LoggingSystem
.
SYSTEM_PROPERTY
);
if
(
this
.
context
!=
null
)
{
if
(
this
.
context
!=
null
)
{
this
.
context
.
close
();
this
.
context
.
close
();
}
}
...
@@ -386,6 +388,37 @@ public class LoggingApplicationListenerTests {
...
@@ -386,6 +388,37 @@ public class LoggingApplicationListenerTests {
TimeUnit
.
SECONDS
),
is
(
true
));
TimeUnit
.
SECONDS
),
is
(
true
));
}
}
@Test
public
void
closingContextCleansUpLoggingSystem
()
{
System
.
setProperty
(
LoggingSystem
.
SYSTEM_PROPERTY
,
TestCleanupLoggingSystem
.
class
.
getName
());
this
.
initializer
.
onApplicationEvent
(
new
ApplicationStartedEvent
(
this
.
springApplication
,
new
String
[
0
]));
TestCleanupLoggingSystem
loggingSystem
=
(
TestCleanupLoggingSystem
)
ReflectionTestUtils
.
getField
(
this
.
initializer
,
"loggingSystem"
);
assertThat
(
loggingSystem
.
cleanedUp
,
is
(
false
));
this
.
initializer
.
onApplicationEvent
(
new
ContextClosedEvent
(
this
.
context
));
assertThat
(
loggingSystem
.
cleanedUp
,
is
(
true
));
}
@Test
public
void
closingChildContextDoesNotCleanUpLoggingSystem
()
{
System
.
setProperty
(
LoggingSystem
.
SYSTEM_PROPERTY
,
TestCleanupLoggingSystem
.
class
.
getName
());
this
.
initializer
.
onApplicationEvent
(
new
ApplicationStartedEvent
(
this
.
springApplication
,
new
String
[
0
]));
TestCleanupLoggingSystem
loggingSystem
=
(
TestCleanupLoggingSystem
)
ReflectionTestUtils
.
getField
(
this
.
initializer
,
"loggingSystem"
);
assertThat
(
loggingSystem
.
cleanedUp
,
is
(
false
));
GenericApplicationContext
childContext
=
new
GenericApplicationContext
();
childContext
.
setParent
(
this
.
context
);
this
.
initializer
.
onApplicationEvent
(
new
ContextClosedEvent
(
childContext
));
assertThat
(
loggingSystem
.
cleanedUp
,
is
(
false
));
this
.
initializer
.
onApplicationEvent
(
new
ContextClosedEvent
(
this
.
context
));
assertThat
(
loggingSystem
.
cleanedUp
,
is
(
true
));
childContext
.
close
();
}
private
boolean
bridgeHandlerInstalled
()
{
private
boolean
bridgeHandlerInstalled
()
{
Logger
rootLogger
=
LogManager
.
getLogManager
().
getLogger
(
""
);
Logger
rootLogger
=
LogManager
.
getLogManager
().
getLogger
(
""
);
Handler
[]
handlers
=
rootLogger
.
getHandlers
();
Handler
[]
handlers
=
rootLogger
.
getHandlers
();
...
@@ -453,4 +486,34 @@ public class LoggingApplicationListenerTests {
...
@@ -453,4 +486,34 @@ public class LoggingApplicationListenerTests {
}
}
public
static
final
class
TestCleanupLoggingSystem
extends
LoggingSystem
{
private
boolean
cleanedUp
=
false
;
public
TestCleanupLoggingSystem
(
ClassLoader
classLoader
)
{
}
@Override
public
void
beforeInitialize
()
{
}
@Override
public
void
initialize
(
String
configLocation
,
LogFile
logFile
)
{
}
@Override
public
void
setLogLevel
(
String
loggerName
,
LogLevel
level
)
{
}
@Override
public
void
cleanUp
()
{
this
.
cleanedUp
=
true
;
}
}
}
}
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