Commit 69b72874 authored by Phillip Webb's avatar Phillip Webb

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
parent 902905ad
/* /*
* Copyright 2012-2016 the original author or authors. * Copyright 2012-2017 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -21,7 +21,7 @@ import javax.validation.Validation; ...@@ -21,7 +21,7 @@ import javax.validation.Validation;
import org.apache.catalina.mbeans.MBeanFactory; import org.apache.catalina.mbeans.MBeanFactory;
import org.springframework.boot.context.event.ApplicationEnvironmentPreparedEvent; import org.springframework.boot.context.event.ApplicationEnvironmentPreparedEvent;
import org.springframework.boot.logging.LoggingApplicationListener; import org.springframework.boot.context.logging.LoggingApplicationListener;
import org.springframework.context.ApplicationListener; import org.springframework.context.ApplicationListener;
import org.springframework.core.annotation.Order; import org.springframework.core.annotation.Order;
import org.springframework.format.support.DefaultFormattingConversionService; import org.springframework.format.support.DefaultFormattingConversionService;
......
...@@ -26,12 +26,12 @@ import org.springframework.boot.SpringApplication; ...@@ -26,12 +26,12 @@ import org.springframework.boot.SpringApplication;
import org.springframework.boot.WebApplicationType; import org.springframework.boot.WebApplicationType;
import org.springframework.boot.context.config.AnsiOutputApplicationListener; import org.springframework.boot.context.config.AnsiOutputApplicationListener;
import org.springframework.boot.context.config.ConfigFileApplicationListener; import org.springframework.boot.context.config.ConfigFileApplicationListener;
import org.springframework.boot.context.logging.ClasspathLoggingApplicationListener;
import org.springframework.boot.context.logging.LoggingApplicationListener;
import org.springframework.boot.devtools.remote.client.RemoteClientConfiguration; import org.springframework.boot.devtools.remote.client.RemoteClientConfiguration;
import org.springframework.boot.devtools.restart.RestartInitializer; import org.springframework.boot.devtools.restart.RestartInitializer;
import org.springframework.boot.devtools.restart.RestartScopeInitializer; import org.springframework.boot.devtools.restart.RestartScopeInitializer;
import org.springframework.boot.devtools.restart.Restarter; import org.springframework.boot.devtools.restart.Restarter;
import org.springframework.boot.logging.ClasspathLoggingApplicationListener;
import org.springframework.boot.logging.LoggingApplicationListener;
import org.springframework.context.ApplicationContextInitializer; import org.springframework.context.ApplicationContextInitializer;
import org.springframework.context.ApplicationListener; import org.springframework.context.ApplicationListener;
import org.springframework.core.io.ClassPathResource; import org.springframework.core.io.ClassPathResource;
......
...@@ -3,6 +3,12 @@ ...@@ -3,6 +3,12 @@
<import-control pkg="org.springframework.boot"> <import-control pkg="org.springframework.boot">
<allow pkg=".*" regex="true" /> <allow pkg=".*" regex="true" />
<!-- Logging -->
<subpackage name="logging">
<disallow pkg="org.springframework.context" />
<disallow pkg="org.springframework.boot.context" />
</subpackage>
<!-- Web related concerns --> <!-- Web related concerns -->
<subpackage name="web"> <subpackage name="web">
......
/* /*
* Copyright 2012-2016 the original author or authors. * Copyright 2012-2017 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
package org.springframework.boot.logging; package org.springframework.boot.context.logging;
import java.net.URLClassLoader; import java.net.URLClassLoader;
import java.util.Arrays; import java.util.Arrays;
...@@ -36,6 +36,7 @@ import org.springframework.core.ResolvableType; ...@@ -36,6 +36,7 @@ import org.springframework.core.ResolvableType;
* context class loader (TCCL) at {@code DEBUG} level. * context class loader (TCCL) at {@code DEBUG} level.
* *
* @author Andy Wilkinson * @author Andy Wilkinson
* @since 2.0.0
*/ */
public final class ClasspathLoggingApplicationListener public final class ClasspathLoggingApplicationListener
implements GenericApplicationListener { implements GenericApplicationListener {
......
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
package org.springframework.boot.logging; package org.springframework.boot.context.logging;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
...@@ -31,6 +31,11 @@ import org.springframework.boot.context.event.ApplicationEnvironmentPreparedEven ...@@ -31,6 +31,11 @@ import org.springframework.boot.context.event.ApplicationEnvironmentPreparedEven
import org.springframework.boot.context.event.ApplicationFailedEvent; import org.springframework.boot.context.event.ApplicationFailedEvent;
import org.springframework.boot.context.event.ApplicationPreparedEvent; import org.springframework.boot.context.event.ApplicationPreparedEvent;
import org.springframework.boot.context.event.ApplicationStartingEvent; import org.springframework.boot.context.event.ApplicationStartingEvent;
import org.springframework.boot.logging.LogFile;
import org.springframework.boot.logging.LogLevel;
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.ApplicationContext;
import org.springframework.context.ApplicationEvent; import org.springframework.context.ApplicationEvent;
import org.springframework.context.ApplicationListener; import org.springframework.context.ApplicationListener;
...@@ -72,6 +77,7 @@ import org.springframework.util.StringUtils; ...@@ -72,6 +77,7 @@ import org.springframework.util.StringUtils;
* @author Dave Syer * @author Dave Syer
* @author Phillip Webb * @author Phillip Webb
* @author Andy Wilkinson * @author Andy Wilkinson
* @since 2.0.0
* @see LoggingSystem#get(ClassLoader) * @see LoggingSystem#get(ClassLoader)
*/ */
public class LoggingApplicationListener implements GenericApplicationListener { public class LoggingApplicationListener implements GenericApplicationListener {
...@@ -94,57 +100,6 @@ public class LoggingApplicationListener implements GenericApplicationListener { ...@@ -94,57 +100,6 @@ public class LoggingApplicationListener implements GenericApplicationListener {
*/ */
public static final String REGISTER_SHUTDOWN_HOOK_PROPERTY = "logging.register-shutdown-hook"; public static final String REGISTER_SHUTDOWN_HOOK_PROPERTY = "logging.register-shutdown-hook";
/**
* The name of the Spring property that contains the directory where log files are
* written.
* @deprecated as of 1.5 in favor of {@link LogFile#PATH_PROPERTY}
*/
@Deprecated
public static final String PATH_PROPERTY = LogFile.PATH_PROPERTY;
/**
* The name of the Spring property that contains the name of the log file. Names can
* be an exact location or relative to the current directory.
* @deprecated as of 1.5 in favor of {@link LogFile#FILE_PROPERTY}
*/
@Deprecated
public static final String FILE_PROPERTY = LogFile.FILE_PROPERTY;
/**
* The name of the System property that contains the process ID.
*/
public static final String PID_KEY = "PID";
/**
* The name of the System property that contains the exception conversion word.
*/
public static final String EXCEPTION_CONVERSION_WORD = "LOG_EXCEPTION_CONVERSION_WORD";
/**
* The name of the System property that contains the log file.
*/
public static final String LOG_FILE = "LOG_FILE";
/**
* The name of the System property that contains the log path.
*/
public static final String LOG_PATH = "LOG_PATH";
/**
* The name of the System property that contains the console log pattern.
*/
public static final String CONSOLE_LOG_PATTERN = "CONSOLE_LOG_PATTERN";
/**
* The name of the System property that contains the file log pattern.
*/
public static final String FILE_LOG_PATTERN = "FILE_LOG_PATTERN";
/**
* The name of the System property that contains the log level pattern.
*/
public static final String LOG_LEVEL_PATTERN = "LOG_LEVEL_PATTERN";
/** /**
* The name of the {@link LoggingSystem} bean. * The name of the {@link LoggingSystem} bean.
*/ */
......
/*
* Copyright 2012-2017 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Logging integration with Spring's Application Context.
*/
package org.springframework.boot.context.logging;
/* /*
* Copyright 2012-2016 the original author or authors. * Copyright 2012-2017 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -83,8 +83,8 @@ public class LogFile { ...@@ -83,8 +83,8 @@ public class LogFile {
* @param properties the properties to apply to * @param properties the properties to apply to
*/ */
public void applyTo(Properties properties) { public void applyTo(Properties properties) {
put(properties, LoggingApplicationListener.LOG_PATH, this.path); put(properties, LoggingSystemProperties.LOG_PATH, this.path);
put(properties, LoggingApplicationListener.LOG_FILE, toString()); put(properties, LoggingSystemProperties.LOG_FILE, toString());
} }
private void put(Properties properties, String key, String value) { private void put(Properties properties, String key, String value) {
......
/* /*
* Copyright 2012-2016 the original author or authors. * Copyright 2012-2017 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -19,28 +19,60 @@ package org.springframework.boot.logging; ...@@ -19,28 +19,60 @@ package org.springframework.boot.logging;
import org.springframework.boot.ApplicationPid; import org.springframework.boot.ApplicationPid;
import org.springframework.boot.bind.RelaxedPropertyResolver; import org.springframework.boot.bind.RelaxedPropertyResolver;
import org.springframework.core.env.Environment; import org.springframework.core.env.Environment;
import org.springframework.util.Assert;
/** /**
* Utility to set system properties that can later be used by log configuration files. * Utility to set system properties that can later be used by log configuration files.
* *
* @author Andy Wilkinson * @author Andy Wilkinson
* @author Phillip Webb * @author Phillip Webb
* @since 2.0.0
*/ */
class LoggingSystemProperties { public class LoggingSystemProperties {
static final String PID_KEY = LoggingApplicationListener.PID_KEY; /**
* The name of the System property that contains the process ID.
*/
public static final String PID_KEY = "PID";
static final String EXCEPTION_CONVERSION_WORD = LoggingApplicationListener.EXCEPTION_CONVERSION_WORD; /**
* The name of the System property that contains the exception conversion word.
*/
public static final String EXCEPTION_CONVERSION_WORD = "LOG_EXCEPTION_CONVERSION_WORD";
static final String CONSOLE_LOG_PATTERN = LoggingApplicationListener.CONSOLE_LOG_PATTERN; /**
* The name of the System property that contains the log file.
*/
public static final String LOG_FILE = "LOG_FILE";
static final String FILE_LOG_PATTERN = LoggingApplicationListener.FILE_LOG_PATTERN; /**
* The name of the System property that contains the log path.
*/
public static final String LOG_PATH = "LOG_PATH";
static final String LOG_LEVEL_PATTERN = LoggingApplicationListener.LOG_LEVEL_PATTERN; /**
* The name of the System property that contains the console log pattern.
*/
public static final String CONSOLE_LOG_PATTERN = "CONSOLE_LOG_PATTERN";
/**
* The name of the System property that contains the file log pattern.
*/
public static final String FILE_LOG_PATTERN = "FILE_LOG_PATTERN";
/**
* The name of the System property that contains the log level pattern.
*/
public static final String LOG_LEVEL_PATTERN = "LOG_LEVEL_PATTERN";
private final Environment environment; private final Environment environment;
LoggingSystemProperties(Environment environment) { /**
* Create a new {@link LoggingSystemProperties} instance.
* @param environment the source environment
*/
public LoggingSystemProperties(Environment environment) {
Assert.notNull(environment, "Environment must not be null");
this.environment = environment; this.environment = environment;
} }
......
...@@ -22,9 +22,9 @@ org.springframework.boot.context.FileEncodingApplicationListener,\ ...@@ -22,9 +22,9 @@ org.springframework.boot.context.FileEncodingApplicationListener,\
org.springframework.boot.context.config.AnsiOutputApplicationListener,\ org.springframework.boot.context.config.AnsiOutputApplicationListener,\
org.springframework.boot.context.config.ConfigFileApplicationListener,\ org.springframework.boot.context.config.ConfigFileApplicationListener,\
org.springframework.boot.context.config.DelegatingApplicationListener,\ org.springframework.boot.context.config.DelegatingApplicationListener,\
org.springframework.boot.liquibase.LiquibaseServiceLocatorApplicationListener,\ org.springframework.boot.context.logging.ClasspathLoggingApplicationListener,\
org.springframework.boot.logging.ClasspathLoggingApplicationListener,\ org.springframework.boot.context.logging.LoggingApplicationListener,\
org.springframework.boot.logging.LoggingApplicationListener org.springframework.boot.liquibase.LiquibaseServiceLocatorApplicationListener
# Environment Post Processors # Environment Post Processors
org.springframework.boot.env.EnvironmentPostProcessor=\ org.springframework.boot.env.EnvironmentPostProcessor=\
......
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
package org.springframework.boot.logging; package org.springframework.boot.context.logging;
import org.junit.Rule; import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
...@@ -24,6 +24,7 @@ import org.slf4j.LoggerFactory; ...@@ -24,6 +24,7 @@ import org.slf4j.LoggerFactory;
import org.springframework.boot.WebApplicationType; import org.springframework.boot.WebApplicationType;
import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.context.event.ApplicationStartingEvent; import org.springframework.boot.context.event.ApplicationStartingEvent;
import org.springframework.boot.logging.LoggingSystem;
import org.springframework.boot.testutil.InternalOutputCapture; import org.springframework.boot.testutil.InternalOutputCapture;
import org.springframework.context.ApplicationListener; import org.springframework.context.ApplicationListener;
import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.ConfigurableApplicationContext;
......
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
package org.springframework.boot.logging; package org.springframework.boot.context.logging;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
...@@ -40,6 +40,12 @@ import org.springframework.boot.ApplicationPid; ...@@ -40,6 +40,12 @@ import org.springframework.boot.ApplicationPid;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
import org.springframework.boot.context.event.ApplicationFailedEvent; import org.springframework.boot.context.event.ApplicationFailedEvent;
import org.springframework.boot.context.event.ApplicationStartingEvent; import org.springframework.boot.context.event.ApplicationStartingEvent;
import org.springframework.boot.logging.AbstractLoggingSystem;
import org.springframework.boot.logging.LogFile;
import org.springframework.boot.logging.LogLevel;
import org.springframework.boot.logging.LoggerConfiguration;
import org.springframework.boot.logging.LoggingInitializationContext;
import org.springframework.boot.logging.LoggingSystem;
import org.springframework.boot.logging.java.JavaLoggingSystem; import org.springframework.boot.logging.java.JavaLoggingSystem;
import org.springframework.boot.testutil.InternalOutputCapture; import org.springframework.boot.testutil.InternalOutputCapture;
import org.springframework.context.ApplicationEvent; import org.springframework.context.ApplicationEvent;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment