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
cedb6b2f
Commit
cedb6b2f
authored
Jan 25, 2018
by
Andy Wilkinson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Revert "Clean up the logging system later in context close processing"
This reverts commit
8619256d
. See gh-11676
parent
d65f9b25
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
46 additions
and
87 deletions
+46
-87
BackgroundPreinitializer.java
...ramework/boot/autoconfigure/BackgroundPreinitializer.java
+2
-2
RemoteSpringApplication.java
...pringframework/boot/devtools/RemoteSpringApplication.java
+3
-3
ClasspathLoggingApplicationListener.java
.../context/logging/ClasspathLoggingApplicationListener.java
+2
-2
LoggingApplicationListener.java
...work/boot/context/logging/LoggingApplicationListener.java
+17
-52
spring.factories
.../spring-boot/src/main/resources/META-INF/spring.factories
+1
-2
SpringApplicationBuilderTests.java
...framework/boot/builder/SpringApplicationBuilderTests.java
+3
-3
LoggingApplicationListenerIntegrationTests.java
...t/logging/LoggingApplicationListenerIntegrationTests.java
+3
-3
LoggingApplicationListenerTests.java
...boot/context/logging/LoggingApplicationListenerTests.java
+15
-20
No files found.
spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/BackgroundPreinitializer.java
View file @
cedb6b2f
...
...
@@ -30,7 +30,7 @@ import org.springframework.boot.context.event.ApplicationFailedEvent;
import
org.springframework.boot.context.event.ApplicationReadyEvent
;
import
org.springframework.boot.context.event.ApplicationStartingEvent
;
import
org.springframework.boot.context.event.SpringApplicationEvent
;
import
org.springframework.boot.context.logging.Logging
SystemLifecycle
;
import
org.springframework.boot.context.logging.Logging
ApplicationListener
;
import
org.springframework.context.ApplicationListener
;
import
org.springframework.core.annotation.Order
;
import
org.springframework.format.support.DefaultFormattingConversionService
;
...
...
@@ -45,7 +45,7 @@ import org.springframework.http.converter.support.AllEncompassingFormHttpMessage
* @author Andy Wilkinson
* @since 1.3.0
*/
@Order
(
Logging
SystemLifecycle
.
DEFAULT_ORDER
+
1
)
@Order
(
Logging
ApplicationListener
.
DEFAULT_ORDER
+
1
)
public
class
BackgroundPreinitializer
implements
ApplicationListener
<
SpringApplicationEvent
>
{
...
...
spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/RemoteSpringApplication.java
View file @
cedb6b2f
/*
* Copyright 2012-201
8
the original author or authors.
* Copyright 2012-201
7
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.
...
...
@@ -27,7 +27,7 @@ import org.springframework.boot.WebApplicationType;
import
org.springframework.boot.context.config.AnsiOutputApplicationListener
;
import
org.springframework.boot.context.config.ConfigFileApplicationListener
;
import
org.springframework.boot.context.logging.ClasspathLoggingApplicationListener
;
import
org.springframework.boot.context.logging.Logging
SystemLifecycle
;
import
org.springframework.boot.context.logging.Logging
ApplicationListener
;
import
org.springframework.boot.devtools.remote.client.RemoteClientConfiguration
;
import
org.springframework.boot.devtools.restart.RestartInitializer
;
import
org.springframework.boot.devtools.restart.RestartScopeInitializer
;
...
...
@@ -74,7 +74,7 @@ public final class RemoteSpringApplication {
listeners
.
add
(
new
AnsiOutputApplicationListener
());
listeners
.
add
(
new
ConfigFileApplicationListener
());
listeners
.
add
(
new
ClasspathLoggingApplicationListener
());
listeners
.
add
(
new
Logging
SystemLifecycle
());
listeners
.
add
(
new
Logging
ApplicationListener
());
listeners
.
add
(
new
RemoteUrlPropertyExtractor
());
return
listeners
;
}
...
...
spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/logging/ClasspathLoggingApplicationListener.java
View file @
cedb6b2f
/*
* Copyright 2012-201
8
the original author or authors.
* Copyright 2012-201
7
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.
...
...
@@ -41,7 +41,7 @@ import org.springframework.core.ResolvableType;
public
final
class
ClasspathLoggingApplicationListener
implements
GenericApplicationListener
{
private
static
final
int
ORDER
=
Logging
SystemLifecycle
.
DEFAULT_ORDER
+
1
;
private
static
final
int
ORDER
=
Logging
ApplicationListener
.
DEFAULT_ORDER
+
1
;
private
static
final
Log
logger
=
LogFactory
.
getLog
(
ClasspathLoggingApplicationListener
.
class
);
...
...
spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/logging/Logging
SystemLifecycle
.java
→
spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/logging/Logging
ApplicationListener
.java
View file @
cedb6b2f
/*
* Copyright 2012-201
8
the original author or authors.
* Copyright 2012-201
7
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.
...
...
@@ -24,12 +24,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
import
org.apache.commons.logging.Log
;
import
org.apache.commons.logging.LogFactory
;
import
org.springframework.beans.factory.BeanFactory
;
import
org.springframework.beans.factory.DisposableBean
;
import
org.springframework.beans.factory.config.BeanDefinition
;
import
org.springframework.beans.factory.config.ConfigurableListableBeanFactory
;
import
org.springframework.beans.factory.support.BeanDefinitionBuilder
;
import
org.springframework.beans.factory.support.BeanDefinitionRegistry
;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.context.event.ApplicationEnvironmentPreparedEvent
;
import
org.springframework.boot.context.event.ApplicationFailedEvent
;
...
...
@@ -43,9 +38,8 @@ import org.springframework.boot.logging.LoggingInitializationContext;
import
org.springframework.boot.logging.LoggingSystem
;
import
org.springframework.boot.logging.LoggingSystemProperties
;
import
org.springframework.context.ApplicationContext
;
import
org.springframework.context.ApplicationContextInitializer
;
import
org.springframework.context.ApplicationEvent
;
import
org.springframework.context.
ConfigurableApplicationContext
;
import
org.springframework.context.
ApplicationListener
;
import
org.springframework.context.event.ContextClosedEvent
;
import
org.springframework.context.event.GenericApplicationListener
;
import
org.springframework.core.Ordered
;
...
...
@@ -58,11 +52,10 @@ import org.springframework.util.ResourceUtils;
import
org.springframework.util.StringUtils
;
/**
* {@code LoggingSystemLifecyle} configures the {@link LoggingSystem} and manages its
* lifecycle. If the environment contains a {@code logging.config} property it will be
* used to bootstrap the logging system, otherwise a default configuration is used.
* Regardless, logging levels will be customized if the environment contains
* {@code logging.level.*} entries.
* An {@link ApplicationListener} that configures the {@link LoggingSystem}. If the
* environment contains a {@code logging.config} property it will be used to bootstrap the
* logging system, otherwise a default configuration is used. Regardless, logging levels
* will be customized if the environment contains {@code logging.level.*} entries.
* <p>
* Debug and trace logging for Spring, Tomcat, Jetty and Hibernate will be enabled when
* the environment contains {@code debug} or {@code trace} properties that aren't set to
...
...
@@ -89,8 +82,7 @@ import org.springframework.util.StringUtils;
* @since 2.0.0
* @see LoggingSystem#get(ClassLoader)
*/
public
class
LoggingSystemLifecycle
implements
GenericApplicationListener
,
ApplicationContextInitializer
<
ConfigurableApplicationContext
>,
Ordered
{
public
class
LoggingApplicationListener
implements
GenericApplicationListener
{
private
static
final
Bindable
<
Map
<
String
,
String
>>
STRING_STRING_MAP
=
Bindable
.
mapOf
(
String
.
class
,
String
.
class
);
...
...
@@ -183,6 +175,10 @@ public class LoggingSystemLifecycle implements GenericApplicationListener,
else
if
(
event
instanceof
ApplicationPreparedEvent
)
{
onApplicationPreparedEvent
((
ApplicationPreparedEvent
)
event
);
}
else
if
(
event
instanceof
ContextClosedEvent
&&
((
ContextClosedEvent
)
event
)
.
getApplicationContext
().
getParent
()
==
null
)
{
onContextClosedEvent
();
}
else
if
(
event
instanceof
ApplicationFailedEvent
)
{
onApplicationFailedEvent
();
}
...
...
@@ -211,6 +207,12 @@ public class LoggingSystemLifecycle implements GenericApplicationListener,
}
}
private
void
onContextClosedEvent
()
{
if
(
this
.
loggingSystem
!=
null
)
{
this
.
loggingSystem
.
cleanUp
();
}
}
private
void
onApplicationFailedEvent
()
{
if
(
this
.
loggingSystem
!=
null
)
{
this
.
loggingSystem
.
cleanUp
();
...
...
@@ -365,41 +367,4 @@ public class LoggingSystemLifecycle implements GenericApplicationListener,
this
.
parseArgs
=
parseArgs
;
}
@Override
public
void
initialize
(
ConfigurableApplicationContext
applicationContext
)
{
registerCleanupBean
(
applicationContext
);
}
private
void
registerCleanupBean
(
ConfigurableApplicationContext
applicationContext
)
{
BeanFactory
beanFactory
=
applicationContext
.
getBeanFactory
();
BeanDefinition
beanDefinition
=
BeanDefinitionBuilder
.
genericBeanDefinition
(
LoggingSystemCleanup
.
class
)
.
addConstructorArgValue
(
this
.
loggingSystem
)
.
addConstructorArgValue
(
applicationContext
).
getBeanDefinition
();
((
BeanDefinitionRegistry
)
beanFactory
).
registerBeanDefinition
(
LoggingSystemCleanup
.
class
.
getName
(),
beanDefinition
);
}
private
static
final
class
LoggingSystemCleanup
implements
DisposableBean
{
private
final
LoggingSystem
loggingSystem
;
private
final
ApplicationContext
applicationContext
;
private
LoggingSystemCleanup
(
LoggingSystem
loggingSystem
,
ApplicationContext
applicationContext
)
{
this
.
loggingSystem
=
loggingSystem
;
this
.
applicationContext
=
applicationContext
;
}
@Override
public
void
destroy
()
throws
Exception
{
if
(
this
.
applicationContext
.
getParent
()
==
null
&&
this
.
loggingSystem
!=
null
)
{
this
.
loggingSystem
.
cleanUp
();
}
}
}
}
spring-boot-project/spring-boot/src/main/resources/META-INF/spring.factories
View file @
cedb6b2f
...
...
@@ -16,7 +16,6 @@ org.springframework.context.ApplicationContextInitializer=\
org.springframework.boot.context.ConfigurationWarningsApplicationContextInitializer,\
org.springframework.boot.context.ContextIdApplicationContextInitializer,\
org.springframework.boot.context.config.DelegatingApplicationContextInitializer,\
org.springframework.boot.context.logging.LoggingSystemLifecycle,\
org.springframework.boot.web.context.ServerPortInfoApplicationContextInitializer
# Application Listeners
...
...
@@ -28,7 +27,7 @@ org.springframework.boot.context.config.AnsiOutputApplicationListener,\
org.springframework.boot.context.config.ConfigFileApplicationListener,\
org.springframework.boot.context.config.DelegatingApplicationListener,\
org.springframework.boot.context.logging.ClasspathLoggingApplicationListener,\
org.springframework.boot.context.logging.Logging
SystemLifecycle
,\
org.springframework.boot.context.logging.Logging
ApplicationListener
,\
org.springframework.boot.liquibase.LiquibaseServiceLocatorApplicationListener
# Environment Post Processors
...
...
spring-boot-project/spring-boot/src/test/java/org/springframework/boot/builder/SpringApplicationBuilderTests.java
View file @
cedb6b2f
...
...
@@ -277,7 +277,7 @@ public class SpringApplicationBuilderTests {
SpringApplicationBuilder
application
=
new
SpringApplicationBuilder
(
ExampleConfig
.
class
).
web
(
WebApplicationType
.
NONE
);
this
.
context
=
application
.
run
();
assertThat
(
application
.
application
().
getInitializers
()).
hasSize
(
5
);
assertThat
(
application
.
application
().
getInitializers
()).
hasSize
(
4
);
}
@Test
...
...
@@ -286,7 +286,7 @@ public class SpringApplicationBuilderTests {
ExampleConfig
.
class
).
child
(
ChildConfig
.
class
)
.
web
(
WebApplicationType
.
NONE
);
this
.
context
=
application
.
run
();
assertThat
(
application
.
application
().
getInitializers
()).
hasSize
(
6
);
assertThat
(
application
.
application
().
getInitializers
()).
hasSize
(
5
);
}
@Test
...
...
@@ -296,7 +296,7 @@ public class SpringApplicationBuilderTests {
(
ConfigurableApplicationContext
applicationContext
)
->
{
});
this
.
context
=
application
.
run
();
assertThat
(
application
.
application
().
getInitializers
()).
hasSize
(
6
);
assertThat
(
application
.
application
().
getInitializers
()).
hasSize
(
5
);
}
@Test
...
...
spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/logging/Logging
SystemLifecycle
IntegrationTests.java
→
spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/logging/Logging
ApplicationListener
IntegrationTests.java
View file @
cedb6b2f
/*
* Copyright 2012-201
8
the original author or authors.
* Copyright 2012-201
7
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.
...
...
@@ -33,11 +33,11 @@ import org.springframework.stereotype.Component;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Integration tests for {@link Logging
SystemLifecycle
}.
* Integration tests for {@link Logging
ApplicationListener
}.
*
* @author Stephane Nicoll
*/
public
class
Logging
SystemLifecycle
IntegrationTests
{
public
class
Logging
ApplicationListener
IntegrationTests
{
@Rule
public
OutputCapture
outputCapture
=
new
OutputCapture
();
...
...
spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/logging/Logging
SystemLifecycle
Tests.java
→
spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/logging/Logging
ApplicationListener
Tests.java
View file @
cedb6b2f
/*
* Copyright 2012-201
8
the original author or authors.
* Copyright 2012-201
7
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.
...
...
@@ -56,6 +56,7 @@ import org.springframework.boot.testsupport.runner.classpath.ClassPathExclusions
import
org.springframework.boot.testsupport.runner.classpath.ModifiedClassPathRunner
;
import
org.springframework.context.ApplicationEvent
;
import
org.springframework.context.ApplicationListener
;
import
org.springframework.context.event.ContextClosedEvent
;
import
org.springframework.context.event.SimpleApplicationEventMulticaster
;
import
org.springframework.context.support.GenericApplicationContext
;
import
org.springframework.core.env.ConfigurableEnvironment
;
...
...
@@ -69,7 +70,7 @@ import static org.hamcrest.Matchers.containsString;
import
static
org
.
hamcrest
.
Matchers
.
not
;
/**
* Tests for {@link Logging
SystemLifecycle
} with Logback.
* Tests for {@link Logging
ApplicationListener
} with Logback.
*
* @author Dave Syer
* @author Phillip Webb
...
...
@@ -79,7 +80,7 @@ import static org.hamcrest.Matchers.not;
*/
@RunWith
(
ModifiedClassPathRunner
.
class
)
@ClassPathExclusions
(
"log4j*.jar"
)
public
class
Logging
SystemLifecycle
Tests
{
public
class
Logging
ApplicationListener
Tests
{
private
static
final
String
[]
NO_ARGS
=
{};
...
...
@@ -92,7 +93,7 @@ public class LoggingSystemLifecycleTests {
@Rule
public
OutputCapture
outputCapture
=
new
OutputCapture
();
private
final
Logging
SystemLifecycle
initializer
=
new
LoggingSystemLifecycle
();
private
final
Logging
ApplicationListener
initializer
=
new
LoggingApplicationListener
();
private
final
Log
logger
=
new
SLF4JLogFactory
().
getInstance
(
getClass
());
...
...
@@ -217,7 +218,7 @@ public class LoggingSystemLifecycleTests {
"logging.file=target/foo.log"
);
this
.
initializer
.
initialize
(
this
.
context
.
getEnvironment
(),
this
.
context
.
getClassLoader
());
Log
logger
=
LogFactory
.
getLog
(
Logging
SystemLifecycle
Tests
.
class
);
Log
logger
=
LogFactory
.
getLog
(
Logging
ApplicationListener
Tests
.
class
);
logger
.
info
(
"Hello world"
);
String
output
=
this
.
outputCapture
.
toString
().
trim
();
assertThat
(
output
).
startsWith
(
"target/foo.log"
);
...
...
@@ -230,7 +231,7 @@ public class LoggingSystemLifecycleTests {
"logging.file=target/foo.log"
);
this
.
initializer
.
initialize
(
this
.
context
.
getEnvironment
(),
this
.
context
.
getClassLoader
());
Log
logger
=
LogFactory
.
getLog
(
Logging
SystemLifecycle
Tests
.
class
);
Log
logger
=
LogFactory
.
getLog
(
Logging
ApplicationListener
Tests
.
class
);
logger
.
info
(
"Hello world"
);
assertThat
(
new
File
(
"target/foo.log"
).
exists
()).
isTrue
();
}
...
...
@@ -242,7 +243,7 @@ public class LoggingSystemLifecycleTests {
"logging.path=target/foo/"
);
this
.
initializer
.
initialize
(
this
.
context
.
getEnvironment
(),
this
.
context
.
getClassLoader
());
Log
logger
=
LogFactory
.
getLog
(
Logging
SystemLifecycle
Tests
.
class
);
Log
logger
=
LogFactory
.
getLog
(
Logging
ApplicationListener
Tests
.
class
);
logger
.
info
(
"Hello world"
);
String
output
=
this
.
outputCapture
.
toString
().
trim
();
assertThat
(
output
).
startsWith
(
"target/foo/spring.log"
);
...
...
@@ -386,10 +387,8 @@ public class LoggingSystemLifecycleTests {
@Test
public
void
bridgeHandlerLifecycle
()
{
this
.
initializer
.
initialize
(
this
.
context
);
this
.
context
.
refresh
();
assertThat
(
bridgeHandlerInstalled
()).
isTrue
();
this
.
context
.
close
(
);
multicastEvent
(
new
ContextClosedEvent
(
this
.
context
)
);
assertThat
(
bridgeHandlerInstalled
()).
isFalse
();
}
...
...
@@ -450,12 +449,10 @@ public class LoggingSystemLifecycleTests {
TestCleanupLoggingSystem
.
class
.
getName
());
multicastEvent
(
new
ApplicationStartingEvent
(
this
.
springApplication
,
new
String
[
0
]));
this
.
initializer
.
initialize
(
this
.
context
);
this
.
context
.
refresh
();
TestCleanupLoggingSystem
loggingSystem
=
(
TestCleanupLoggingSystem
)
ReflectionTestUtils
.
getField
(
this
.
initializer
,
"loggingSystem"
);
assertThat
(
loggingSystem
.
cleanedUp
).
isFalse
();
this
.
context
.
close
(
);
multicastEvent
(
new
ContextClosedEvent
(
this
.
context
)
);
assertThat
(
loggingSystem
.
cleanedUp
).
isTrue
();
}
...
...
@@ -465,19 +462,16 @@ public class LoggingSystemLifecycleTests {
TestCleanupLoggingSystem
.
class
.
getName
());
multicastEvent
(
new
ApplicationStartingEvent
(
this
.
springApplication
,
new
String
[
0
]));
this
.
initializer
.
initialize
(
this
.
context
);
this
.
context
.
refresh
();
TestCleanupLoggingSystem
loggingSystem
=
(
TestCleanupLoggingSystem
)
ReflectionTestUtils
.
getField
(
this
.
initializer
,
"loggingSystem"
);
assertThat
(
loggingSystem
.
cleanedUp
).
isFalse
();
GenericApplicationContext
childContext
=
new
GenericApplicationContext
();
childContext
.
setParent
(
this
.
context
);
this
.
initializer
.
initialize
(
childContext
);
childContext
.
refresh
();
childContext
.
close
();
multicastEvent
(
new
ContextClosedEvent
(
childContext
));
assertThat
(
loggingSystem
.
cleanedUp
).
isFalse
();
this
.
context
.
close
(
);
multicastEvent
(
new
ContextClosedEvent
(
this
.
context
)
);
assertThat
(
loggingSystem
.
cleanedUp
).
isTrue
();
childContext
.
close
();
}
@Test
...
...
@@ -619,7 +613,8 @@ public class LoggingSystemLifecycleTests {
}
public
static
class
TestLoggingApplicationListener
extends
LoggingSystemLifecycle
{
public
static
class
TestLoggingApplicationListener
extends
LoggingApplicationListener
{
private
Thread
shutdownHook
;
...
...
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