Skip to content

Commit 69b7287

Browse files
committed
Extract logging listeners
Separate logging ApplicationListeners classes to a different package so that the root `logging` package is no longer aware of `context` concerns. Fixes gh-8611
1 parent 902905a commit 69b7287

File tree

11 files changed

+95
-74
lines changed

11 files changed

+95
-74
lines changed

spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/BackgroundPreinitializer.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2016 the original author or authors.
2+
* Copyright 2012-2017 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -21,7 +21,7 @@
2121
import org.apache.catalina.mbeans.MBeanFactory;
2222

2323
import org.springframework.boot.context.event.ApplicationEnvironmentPreparedEvent;
24-
import org.springframework.boot.logging.LoggingApplicationListener;
24+
import org.springframework.boot.context.logging.LoggingApplicationListener;
2525
import org.springframework.context.ApplicationListener;
2626
import org.springframework.core.annotation.Order;
2727
import org.springframework.format.support.DefaultFormattingConversionService;

spring-boot-devtools/src/main/java/org/springframework/boot/devtools/RemoteSpringApplication.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@
2626
import org.springframework.boot.WebApplicationType;
2727
import org.springframework.boot.context.config.AnsiOutputApplicationListener;
2828
import org.springframework.boot.context.config.ConfigFileApplicationListener;
29+
import org.springframework.boot.context.logging.ClasspathLoggingApplicationListener;
30+
import org.springframework.boot.context.logging.LoggingApplicationListener;
2931
import org.springframework.boot.devtools.remote.client.RemoteClientConfiguration;
3032
import org.springframework.boot.devtools.restart.RestartInitializer;
3133
import org.springframework.boot.devtools.restart.RestartScopeInitializer;
3234
import org.springframework.boot.devtools.restart.Restarter;
33-
import org.springframework.boot.logging.ClasspathLoggingApplicationListener;
34-
import org.springframework.boot.logging.LoggingApplicationListener;
3535
import org.springframework.context.ApplicationContextInitializer;
3636
import org.springframework.context.ApplicationListener;
3737
import org.springframework.core.io.ClassPathResource;

spring-boot-parent/src/checkstyle/import-control.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@
33
<import-control pkg="org.springframework.boot">
44
<allow pkg=".*" regex="true" />
55

6+
<!-- Logging -->
7+
<subpackage name="logging">
8+
<disallow pkg="org.springframework.context" />
9+
<disallow pkg="org.springframework.boot.context" />
10+
</subpackage>
11+
612
<!-- Web related concerns -->
713
<subpackage name="web">
814

spring-boot/src/main/java/org/springframework/boot/logging/ClasspathLoggingApplicationListener.java renamed to spring-boot/src/main/java/org/springframework/boot/context/logging/ClasspathLoggingApplicationListener.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2016 the original author or authors.
2+
* Copyright 2012-2017 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
package org.springframework.boot.logging;
17+
package org.springframework.boot.context.logging;
1818

1919
import java.net.URLClassLoader;
2020
import java.util.Arrays;
@@ -36,6 +36,7 @@
3636
* context class loader (TCCL) at {@code DEBUG} level.
3737
*
3838
* @author Andy Wilkinson
39+
* @since 2.0.0
3940
*/
4041
public final class ClasspathLoggingApplicationListener
4142
implements GenericApplicationListener {

spring-boot/src/main/java/org/springframework/boot/logging/LoggingApplicationListener.java renamed to spring-boot/src/main/java/org/springframework/boot/context/logging/LoggingApplicationListener.java

Lines changed: 7 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
package org.springframework.boot.logging;
17+
package org.springframework.boot.context.logging;
1818

1919
import java.util.List;
2020
import java.util.Map;
@@ -31,6 +31,11 @@
3131
import org.springframework.boot.context.event.ApplicationFailedEvent;
3232
import org.springframework.boot.context.event.ApplicationPreparedEvent;
3333
import org.springframework.boot.context.event.ApplicationStartingEvent;
34+
import org.springframework.boot.logging.LogFile;
35+
import org.springframework.boot.logging.LogLevel;
36+
import org.springframework.boot.logging.LoggingInitializationContext;
37+
import org.springframework.boot.logging.LoggingSystem;
38+
import org.springframework.boot.logging.LoggingSystemProperties;
3439
import org.springframework.context.ApplicationContext;
3540
import org.springframework.context.ApplicationEvent;
3641
import org.springframework.context.ApplicationListener;
@@ -72,6 +77,7 @@
7277
* @author Dave Syer
7378
* @author Phillip Webb
7479
* @author Andy Wilkinson
80+
* @since 2.0.0
7581
* @see LoggingSystem#get(ClassLoader)
7682
*/
7783
public class LoggingApplicationListener implements GenericApplicationListener {
@@ -94,57 +100,6 @@ public class LoggingApplicationListener implements GenericApplicationListener {
94100
*/
95101
public static final String REGISTER_SHUTDOWN_HOOK_PROPERTY = "logging.register-shutdown-hook";
96102

97-
/**
98-
* The name of the Spring property that contains the directory where log files are
99-
* written.
100-
* @deprecated as of 1.5 in favor of {@link LogFile#PATH_PROPERTY}
101-
*/
102-
@Deprecated
103-
public static final String PATH_PROPERTY = LogFile.PATH_PROPERTY;
104-
105-
/**
106-
* The name of the Spring property that contains the name of the log file. Names can
107-
* be an exact location or relative to the current directory.
108-
* @deprecated as of 1.5 in favor of {@link LogFile#FILE_PROPERTY}
109-
*/
110-
@Deprecated
111-
public static final String FILE_PROPERTY = LogFile.FILE_PROPERTY;
112-
113-
/**
114-
* The name of the System property that contains the process ID.
115-
*/
116-
public static final String PID_KEY = "PID";
117-
118-
/**
119-
* The name of the System property that contains the exception conversion word.
120-
*/
121-
public static final String EXCEPTION_CONVERSION_WORD = "LOG_EXCEPTION_CONVERSION_WORD";
122-
123-
/**
124-
* The name of the System property that contains the log file.
125-
*/
126-
public static final String LOG_FILE = "LOG_FILE";
127-
128-
/**
129-
* The name of the System property that contains the log path.
130-
*/
131-
public static final String LOG_PATH = "LOG_PATH";
132-
133-
/**
134-
* The name of the System property that contains the console log pattern.
135-
*/
136-
public static final String CONSOLE_LOG_PATTERN = "CONSOLE_LOG_PATTERN";
137-
138-
/**
139-
* The name of the System property that contains the file log pattern.
140-
*/
141-
public static final String FILE_LOG_PATTERN = "FILE_LOG_PATTERN";
142-
143-
/**
144-
* The name of the System property that contains the log level pattern.
145-
*/
146-
public static final String LOG_LEVEL_PATTERN = "LOG_LEVEL_PATTERN";
147-
148103
/**
149104
* The name of the {@link LoggingSystem} bean.
150105
*/
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*
2+
* Copyright 2012-2017 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
/**
18+
* Logging integration with Spring's Application Context.
19+
*/
20+
package org.springframework.boot.context.logging;

spring-boot/src/main/java/org/springframework/boot/logging/LogFile.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2016 the original author or authors.
2+
* Copyright 2012-2017 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -83,8 +83,8 @@ public void applyToSystemProperties() {
8383
* @param properties the properties to apply to
8484
*/
8585
public void applyTo(Properties properties) {
86-
put(properties, LoggingApplicationListener.LOG_PATH, this.path);
87-
put(properties, LoggingApplicationListener.LOG_FILE, toString());
86+
put(properties, LoggingSystemProperties.LOG_PATH, this.path);
87+
put(properties, LoggingSystemProperties.LOG_FILE, toString());
8888
}
8989

9090
private void put(Properties properties, String key, String value) {

spring-boot/src/main/java/org/springframework/boot/logging/LoggingSystemProperties.java

Lines changed: 40 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2016 the original author or authors.
2+
* Copyright 2012-2017 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -19,28 +19,60 @@
1919
import org.springframework.boot.ApplicationPid;
2020
import org.springframework.boot.bind.RelaxedPropertyResolver;
2121
import org.springframework.core.env.Environment;
22+
import org.springframework.util.Assert;
2223

2324
/**
2425
* Utility to set system properties that can later be used by log configuration files.
2526
*
2627
* @author Andy Wilkinson
2728
* @author Phillip Webb
29+
* @since 2.0.0
2830
*/
29-
class LoggingSystemProperties {
31+
public class LoggingSystemProperties {
3032

31-
static final String PID_KEY = LoggingApplicationListener.PID_KEY;
33+
/**
34+
* The name of the System property that contains the process ID.
35+
*/
36+
public static final String PID_KEY = "PID";
3237

33-
static final String EXCEPTION_CONVERSION_WORD = LoggingApplicationListener.EXCEPTION_CONVERSION_WORD;
38+
/**
39+
* The name of the System property that contains the exception conversion word.
40+
*/
41+
public static final String EXCEPTION_CONVERSION_WORD = "LOG_EXCEPTION_CONVERSION_WORD";
3442

35-
static final String CONSOLE_LOG_PATTERN = LoggingApplicationListener.CONSOLE_LOG_PATTERN;
43+
/**
44+
* The name of the System property that contains the log file.
45+
*/
46+
public static final String LOG_FILE = "LOG_FILE";
3647

37-
static final String FILE_LOG_PATTERN = LoggingApplicationListener.FILE_LOG_PATTERN;
48+
/**
49+
* The name of the System property that contains the log path.
50+
*/
51+
public static final String LOG_PATH = "LOG_PATH";
3852

39-
static final String LOG_LEVEL_PATTERN = LoggingApplicationListener.LOG_LEVEL_PATTERN;
53+
/**
54+
* The name of the System property that contains the console log pattern.
55+
*/
56+
public static final String CONSOLE_LOG_PATTERN = "CONSOLE_LOG_PATTERN";
57+
58+
/**
59+
* The name of the System property that contains the file log pattern.
60+
*/
61+
public static final String FILE_LOG_PATTERN = "FILE_LOG_PATTERN";
62+
63+
/**
64+
* The name of the System property that contains the log level pattern.
65+
*/
66+
public static final String LOG_LEVEL_PATTERN = "LOG_LEVEL_PATTERN";
4067

4168
private final Environment environment;
4269

43-
LoggingSystemProperties(Environment environment) {
70+
/**
71+
* Create a new {@link LoggingSystemProperties} instance.
72+
* @param environment the source environment
73+
*/
74+
public LoggingSystemProperties(Environment environment) {
75+
Assert.notNull(environment, "Environment must not be null");
4476
this.environment = environment;
4577
}
4678

spring-boot/src/main/resources/META-INF/spring.factories

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ org.springframework.boot.context.FileEncodingApplicationListener,\
2222
org.springframework.boot.context.config.AnsiOutputApplicationListener,\
2323
org.springframework.boot.context.config.ConfigFileApplicationListener,\
2424
org.springframework.boot.context.config.DelegatingApplicationListener,\
25-
org.springframework.boot.liquibase.LiquibaseServiceLocatorApplicationListener,\
26-
org.springframework.boot.logging.ClasspathLoggingApplicationListener,\
27-
org.springframework.boot.logging.LoggingApplicationListener
25+
org.springframework.boot.context.logging.ClasspathLoggingApplicationListener,\
26+
org.springframework.boot.context.logging.LoggingApplicationListener,\
27+
org.springframework.boot.liquibase.LiquibaseServiceLocatorApplicationListener
2828

2929
# Environment Post Processors
3030
org.springframework.boot.env.EnvironmentPostProcessor=\

spring-boot/src/test/java/org/springframework/boot/logging/LoggingApplicationListenerIntegrationTests.java renamed to spring-boot/src/test/java/org/springframework/boot/context/logging/LoggingApplicationListenerIntegrationTests.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
package org.springframework.boot.logging;
17+
package org.springframework.boot.context.logging;
1818

1919
import org.junit.Rule;
2020
import org.junit.Test;
@@ -24,6 +24,7 @@
2424
import org.springframework.boot.WebApplicationType;
2525
import org.springframework.boot.builder.SpringApplicationBuilder;
2626
import org.springframework.boot.context.event.ApplicationStartingEvent;
27+
import org.springframework.boot.logging.LoggingSystem;
2728
import org.springframework.boot.testutil.InternalOutputCapture;
2829
import org.springframework.context.ApplicationListener;
2930
import org.springframework.context.ConfigurableApplicationContext;

spring-boot/src/test/java/org/springframework/boot/logging/LoggingApplicationListenerTests.java renamed to spring-boot/src/test/java/org/springframework/boot/context/logging/LoggingApplicationListenerTests.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
package org.springframework.boot.logging;
17+
package org.springframework.boot.context.logging;
1818

1919
import java.io.File;
2020
import java.io.IOException;
@@ -40,6 +40,12 @@
4040
import org.springframework.boot.SpringApplication;
4141
import org.springframework.boot.context.event.ApplicationFailedEvent;
4242
import org.springframework.boot.context.event.ApplicationStartingEvent;
43+
import org.springframework.boot.logging.AbstractLoggingSystem;
44+
import org.springframework.boot.logging.LogFile;
45+
import org.springframework.boot.logging.LogLevel;
46+
import org.springframework.boot.logging.LoggerConfiguration;
47+
import org.springframework.boot.logging.LoggingInitializationContext;
48+
import org.springframework.boot.logging.LoggingSystem;
4349
import org.springframework.boot.logging.java.JavaLoggingSystem;
4450
import org.springframework.boot.testutil.InternalOutputCapture;
4551
import org.springframework.context.ApplicationEvent;

0 commit comments

Comments
 (0)