Remove deprecated logging properties
This commit is contained in:
parent
0fd6b44494
commit
c1a9cd12d6
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2012-2019 the original author or authors.
|
||||
* Copyright 2012-2020 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,16 +56,15 @@ public class LogFileWebEndpointAutoConfiguration {
|
|||
|
||||
private static class LogFileCondition extends SpringBootCondition {
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) {
|
||||
Environment environment = context.getEnvironment();
|
||||
String config = getLogFileConfig(environment, LogFile.FILE_NAME_PROPERTY, LogFile.FILE_PROPERTY);
|
||||
String config = getLogFileConfig(environment, LogFile.FILE_NAME_PROPERTY);
|
||||
ConditionMessage.Builder message = ConditionMessage.forCondition("Log File");
|
||||
if (StringUtils.hasText(config)) {
|
||||
return ConditionOutcome.match(message.found(LogFile.FILE_NAME_PROPERTY).items(config));
|
||||
}
|
||||
config = getLogFileConfig(environment, LogFile.FILE_PATH_PROPERTY, LogFile.PATH_PROPERTY);
|
||||
config = getLogFileConfig(environment, LogFile.FILE_PATH_PROPERTY);
|
||||
if (StringUtils.hasText(config)) {
|
||||
return ConditionOutcome.match(message.found(LogFile.FILE_PATH_PROPERTY).items(config));
|
||||
}
|
||||
|
@ -76,12 +75,8 @@ public class LogFileWebEndpointAutoConfiguration {
|
|||
return ConditionOutcome.noMatch(message.didNotFind("logging file").atAll());
|
||||
}
|
||||
|
||||
private String getLogFileConfig(Environment environment, String configName, String deprecatedConfigName) {
|
||||
String config = environment.resolvePlaceholders("${" + configName + ":}");
|
||||
if (StringUtils.hasText(config)) {
|
||||
return config;
|
||||
}
|
||||
return environment.resolvePlaceholders("${" + deprecatedConfigName + ":}");
|
||||
private String getLogFileConfig(Environment environment, String configName) {
|
||||
return environment.resolvePlaceholders("${" + configName + ":}");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2012-2019 the original author or authors.
|
||||
* Copyright 2012-2020 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.
|
||||
|
@ -64,14 +64,6 @@ class LogFileWebEndpointAutoConfigurationTests {
|
|||
.run((context) -> assertThat(context).hasSingleBean(LogFileWebEndpoint.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Deprecated
|
||||
void runWhenLoggingFileIsSetWithDeprecatedPropertyAndExposedShouldHaveEndpointBean() {
|
||||
this.contextRunner
|
||||
.withPropertyValues("logging.file:test.log", "management.endpoints.web.exposure.include=logfile")
|
||||
.run((context) -> assertThat(context).hasSingleBean(LogFileWebEndpoint.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
void runWhenLoggingPathIsSetAndNotExposedShouldNotHaveEndpointBean() {
|
||||
this.contextRunner.withPropertyValues("logging.file.path:test/logs")
|
||||
|
@ -85,14 +77,6 @@ class LogFileWebEndpointAutoConfigurationTests {
|
|||
.run((context) -> assertThat(context).hasSingleBean(LogFileWebEndpoint.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Deprecated
|
||||
void runWhenLoggingPathIsSetWithDeprecatedPropertyAndExposedShouldHaveEndpointBean() {
|
||||
this.contextRunner
|
||||
.withPropertyValues("logging.path:test/logs", "management.endpoints.web.exposure.include=logfile")
|
||||
.run((context) -> assertThat(context).hasSingleBean(LogFileWebEndpoint.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
void logFileWebEndpointIsAutoConfiguredWhenExternalFileIsSet() {
|
||||
this.contextRunner
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2012-2019 the original author or authors.
|
||||
* Copyright 2012-2020 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.
|
||||
|
@ -74,16 +74,6 @@ class LogFileWebEndpointTests {
|
|||
assertThat(contentOf(resource.getFile())).isEqualTo("--TEST--");
|
||||
}
|
||||
|
||||
@Test
|
||||
@Deprecated
|
||||
void resourceResponseWithLogFileAndDeprecatedProperty() throws Exception {
|
||||
this.environment.setProperty("logging.file", this.logFile.getAbsolutePath());
|
||||
LogFileWebEndpoint endpoint = new LogFileWebEndpoint(LogFile.get(this.environment), null);
|
||||
Resource resource = endpoint.logFile();
|
||||
assertThat(resource).isNotNull();
|
||||
assertThat(contentOf(resource.getFile())).isEqualTo("--TEST--");
|
||||
}
|
||||
|
||||
@Test
|
||||
void resourceResponseWithExternalLogFile() throws Exception {
|
||||
LogFileWebEndpoint endpoint = new LogFileWebEndpoint(null, this.logFile);
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2012-2019 the original author or authors.
|
||||
* Copyright 2012-2020 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.
|
||||
|
@ -74,7 +74,7 @@ class LogFileWebEndpointWebIntegrationTests {
|
|||
File logFile = new File(tempFile, "test.log");
|
||||
FileCopyUtils.copy("--TEST--".getBytes(), logFile);
|
||||
MockEnvironment environment = new MockEnvironment();
|
||||
environment.setProperty("logging.file", logFile.getAbsolutePath());
|
||||
environment.setProperty("logging.file.name", logFile.getAbsolutePath());
|
||||
return new LogFileWebEndpoint(LogFile.get(environment), null);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2012-2019 the original author or authors.
|
||||
* Copyright 2012-2020 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.
|
||||
|
@ -136,13 +136,6 @@ public class LoggingApplicationListener implements GenericApplicationListener {
|
|||
*/
|
||||
public static final String LOGGER_GROUPS_BEAN_NAME = "springBootLoggerGroups";
|
||||
|
||||
/**
|
||||
* The name of the {@link LogFile} bean.
|
||||
* @deprecated since 2.2.0 in favor of {@link #LOG_FILE_BEAN_NAME}
|
||||
*/
|
||||
@Deprecated
|
||||
public static final String LOGFILE_BEAN_NAME = LOG_FILE_BEAN_NAME;
|
||||
|
||||
private static final Map<String, List<String>> DEFAULT_GROUP_LOGGERS;
|
||||
static {
|
||||
MultiValueMap<String, String> loggers = new LinkedMultiValueMap<>();
|
||||
|
@ -333,7 +326,7 @@ public class LoggingApplicationListener implements GenericApplicationListener {
|
|||
private void initializeFinalLoggingLevels(ConfigurableEnvironment environment, LoggingSystem system) {
|
||||
bindLoggerGroups(environment);
|
||||
if (this.springBootLogging != null) {
|
||||
initializeLogLevel(system, this.springBootLogging);
|
||||
initializeSpringBootLogging(system, this.springBootLogging);
|
||||
}
|
||||
setLogLevels(system, environment);
|
||||
}
|
||||
|
@ -345,19 +338,6 @@ public class LoggingApplicationListener implements GenericApplicationListener {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize loggers based on the {@link #setSpringBootLogging(LogLevel)
|
||||
* springBootLogging} setting.
|
||||
* @param system the logging system
|
||||
* @param springBootLogging the spring boot logging level requested
|
||||
* @deprecated since 2.2.0 in favor of
|
||||
* {@link #initializeSpringBootLogging(LoggingSystem, LogLevel)}
|
||||
*/
|
||||
@Deprecated
|
||||
protected void initializeLogLevel(LoggingSystem system, LogLevel springBootLogging) {
|
||||
initializeSpringBootLogging(system, springBootLogging);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize loggers based on the {@link #setSpringBootLogging(LogLevel)
|
||||
* springBootLogging} setting. By default this implementation will pick an appropriate
|
||||
|
@ -372,20 +352,6 @@ public class LoggingApplicationListener implements GenericApplicationListener {
|
|||
.forEach((name) -> configureLogLevel(name, springBootLogging, configurer));
|
||||
}
|
||||
|
||||
/**
|
||||
* Set logging levels based on relevant {@link Environment} properties.
|
||||
* @param system the logging system
|
||||
* @param environment the environment
|
||||
* @deprecated since 2.2.0 in favor of
|
||||
* {@link #setLogLevels(LoggingSystem, ConfigurableEnvironment)}
|
||||
*/
|
||||
@Deprecated
|
||||
protected void setLogLevels(LoggingSystem system, Environment environment) {
|
||||
if (environment instanceof ConfigurableEnvironment) {
|
||||
setLogLevels(system, (ConfigurableEnvironment) environment);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set logging levels based on relevant {@link Environment} properties.
|
||||
* @param system the logging system
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2012-2019 the original author or authors.
|
||||
* Copyright 2012-2020 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.
|
||||
|
@ -37,22 +37,6 @@ import org.springframework.util.StringUtils;
|
|||
*/
|
||||
public class LogFile {
|
||||
|
||||
/**
|
||||
* 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 since 2.2.0 in favor of {@link #FILE_NAME_PROPERTY}
|
||||
*/
|
||||
@Deprecated
|
||||
public static final String FILE_PROPERTY = "logging.file";
|
||||
|
||||
/**
|
||||
* The name of the Spring property that contains the directory where log files are
|
||||
* written.
|
||||
* @deprecated since 2.2.0 in favor of {@link #FILE_PATH_PROPERTY}
|
||||
*/
|
||||
@Deprecated
|
||||
public static final String PATH_PROPERTY = "logging.path";
|
||||
|
||||
/**
|
||||
* 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.
|
||||
|
@ -128,21 +112,12 @@ public class LogFile {
|
|||
* suitable properties
|
||||
*/
|
||||
public static LogFile get(PropertyResolver propertyResolver) {
|
||||
String file = getLogFileProperty(propertyResolver, FILE_NAME_PROPERTY, FILE_PROPERTY);
|
||||
String path = getLogFileProperty(propertyResolver, FILE_PATH_PROPERTY, PATH_PROPERTY);
|
||||
String file = propertyResolver.getProperty(FILE_NAME_PROPERTY);
|
||||
String path = propertyResolver.getProperty(FILE_PATH_PROPERTY);
|
||||
if (StringUtils.hasLength(file) || StringUtils.hasLength(path)) {
|
||||
return new LogFile(file, path);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static String getLogFileProperty(PropertyResolver propertyResolver, String propertyName,
|
||||
String deprecatedPropertyName) {
|
||||
String property = propertyResolver.getProperty(propertyName);
|
||||
if (property != null) {
|
||||
return property;
|
||||
}
|
||||
return propertyResolver.getProperty(deprecatedPropertyName);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -85,7 +85,8 @@
|
|||
"description": "Log file name (for instance, `myapp.log`). Names can be an exact location or relative to the current directory.",
|
||||
"sourceType": "org.springframework.boot.context.logging.LoggingApplicationListener",
|
||||
"deprecation": {
|
||||
"replacement": "logging.file.name"
|
||||
"replacement": "logging.file.name",
|
||||
"level": "error"
|
||||
}
|
||||
},
|
||||
{
|
||||
|
@ -146,7 +147,8 @@
|
|||
"description": "Location of the log file. For instance, `/var/log`.",
|
||||
"sourceType": "org.springframework.boot.context.logging.LoggingApplicationListener",
|
||||
"deprecation": {
|
||||
"replacement": "logging.file.path"
|
||||
"replacement": "logging.file.path",
|
||||
"level": "error"
|
||||
}
|
||||
},
|
||||
{
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2012-2019 the original author or authors.
|
||||
* Copyright 2012-2020 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.
|
||||
|
@ -59,7 +59,7 @@ class LoggingApplicationListenerIntegrationTests {
|
|||
void logFileRegisteredInTheContextWhenApplicable(@TempDir File tempDir) throws Exception {
|
||||
String logFile = new File(tempDir, "test.log").getAbsolutePath();
|
||||
try (ConfigurableApplicationContext context = new SpringApplicationBuilder(SampleService.class)
|
||||
.web(WebApplicationType.NONE).properties("logging.file=" + logFile).run()) {
|
||||
.web(WebApplicationType.NONE).properties("logging.file.name=" + logFile).run()) {
|
||||
SampleService service = context.getBean(SampleService.class);
|
||||
assertThat(service.logFile).isNotNull();
|
||||
assertThat(service.logFile.toString()).isEqualTo(logFile);
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2012-2019 the original author or authors.
|
||||
* Copyright 2012-2020 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.
|
||||
|
@ -212,19 +212,6 @@ class LoggingApplicationListenerTests {
|
|||
assertThat(output).startsWith(this.logFile.getAbsolutePath());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Deprecated
|
||||
void addLogFilePropertyWithDeprecatedProperty() {
|
||||
addPropertiesToEnvironment(this.context, "logging.config=classpath:logback-nondefault.xml",
|
||||
"logging.file=" + this.logFile);
|
||||
this.initializer.initialize(this.context.getEnvironment(), this.context.getClassLoader());
|
||||
Log logger = LogFactory.getLog(LoggingApplicationListenerTests.class);
|
||||
String existingOutput = this.output.toString();
|
||||
logger.info("Hello world");
|
||||
String output = this.output.toString().substring(existingOutput.length()).trim();
|
||||
assertThat(output).startsWith(this.logFile.getAbsolutePath());
|
||||
}
|
||||
|
||||
@Test
|
||||
void addLogFilePropertyWithDefault() {
|
||||
assertThat(this.logFile).doesNotExist();
|
||||
|
@ -235,16 +222,6 @@ class LoggingApplicationListenerTests {
|
|||
assertThat(this.logFile).isFile();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Deprecated
|
||||
void addLogFilePropertyWithDefaultAndDeprecatedProperty() {
|
||||
addPropertiesToEnvironment(this.context, "logging.file=" + this.logFile);
|
||||
this.initializer.initialize(this.context.getEnvironment(), this.context.getClassLoader());
|
||||
Log logger = LogFactory.getLog(LoggingApplicationListenerTests.class);
|
||||
logger.info("Hello world");
|
||||
assertThat(this.logFile).isFile();
|
||||
}
|
||||
|
||||
@Test
|
||||
void addLogPathProperty() {
|
||||
addPropertiesToEnvironment(this.context, "logging.config=classpath:logback-nondefault.xml",
|
||||
|
@ -257,18 +234,6 @@ class LoggingApplicationListenerTests {
|
|||
assertThat(output).startsWith(new File(this.tempDir.toFile(), "spring.log").getAbsolutePath());
|
||||
}
|
||||
|
||||
@Test
|
||||
void addLogPathPropertyWithDeprecatedProperty() {
|
||||
addPropertiesToEnvironment(this.context, "logging.config=classpath:logback-nondefault.xml",
|
||||
"logging.path=" + this.tempDir);
|
||||
this.initializer.initialize(this.context.getEnvironment(), this.context.getClassLoader());
|
||||
Log logger = LogFactory.getLog(LoggingApplicationListenerTests.class);
|
||||
String existingOutput = this.output.toString();
|
||||
logger.info("Hello world");
|
||||
String output = this.output.toString().substring(existingOutput.length()).trim();
|
||||
assertThat(output).startsWith(new File(this.tempDir.toFile(), "spring.log").getAbsolutePath());
|
||||
}
|
||||
|
||||
@Test
|
||||
void parseDebugArg() {
|
||||
addPropertiesToEnvironment(this.context, "debug");
|
||||
|
@ -495,15 +460,6 @@ class LoggingApplicationListenerTests {
|
|||
assertThat(System.getProperty(LoggingSystemProperties.PID_KEY)).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Deprecated
|
||||
void systemPropertiesAreSetForLoggingConfigurationWithDeprecatedProperties() {
|
||||
addPropertiesToEnvironment(this.context, "logging.file=" + this.logFile, "logging.path=path");
|
||||
this.initializer.initialize(this.context.getEnvironment(), this.context.getClassLoader());
|
||||
assertThat(System.getProperty(LoggingSystemProperties.LOG_FILE)).isEqualTo(this.logFile.getAbsolutePath());
|
||||
assertThat(System.getProperty(LoggingSystemProperties.LOG_PATH)).isEqualTo("path");
|
||||
}
|
||||
|
||||
@Test
|
||||
void environmentPropertiesIgnoreUnresolvablePlaceholders() {
|
||||
// gh-7719
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2012-2019 the original author or authors.
|
||||
* Copyright 2012-2020 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.
|
||||
|
@ -52,13 +52,6 @@ class LogFileTests {
|
|||
testLoggingFile(resolver);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Deprecated
|
||||
void loggingFileWithDeprecatedProperties() {
|
||||
PropertyResolver resolver = getPropertyResolver(Collections.singletonMap("logging.file", "log.file"));
|
||||
testLoggingFile(resolver);
|
||||
}
|
||||
|
||||
private void testLoggingFile(PropertyResolver resolver) {
|
||||
LogFile logFile = LogFile.get(resolver);
|
||||
Properties properties = new Properties();
|
||||
|
@ -74,13 +67,6 @@ class LogFileTests {
|
|||
testLoggingPath(resolver);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Deprecated
|
||||
void loggingPathWithDeprecatedProperties() {
|
||||
PropertyResolver resolver = getPropertyResolver(Collections.singletonMap("logging.path", "logpath"));
|
||||
testLoggingPath(resolver);
|
||||
}
|
||||
|
||||
private void testLoggingPath(PropertyResolver resolver) {
|
||||
LogFile logFile = LogFile.get(resolver);
|
||||
Properties properties = new Properties();
|
||||
|
@ -100,16 +86,6 @@ class LogFileTests {
|
|||
testLoggingFileAndPath(resolver);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Deprecated
|
||||
void loggingFileAndPathWithDeprecatedProperties() {
|
||||
Map<String, Object> properties = new LinkedHashMap<>();
|
||||
properties.put("logging.file", "log.file");
|
||||
properties.put("logging.path", "logpath");
|
||||
PropertyResolver resolver = getPropertyResolver(properties);
|
||||
testLoggingFileAndPath(resolver);
|
||||
}
|
||||
|
||||
private void testLoggingFileAndPath(PropertyResolver resolver) {
|
||||
LogFile logFile = LogFile.get(resolver);
|
||||
Properties properties = new Properties();
|
||||
|
|
Loading…
Reference in New Issue