Skip to content

Commit 7031a3b

Browse files
scottfredericksnicoll
authored andcommitted
Remove deprecated logging properties
See gh-19699
1 parent 421c464 commit 7031a3b

File tree

10 files changed

+22
-178
lines changed

10 files changed

+22
-178
lines changed

Diff for: spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/logging/LogFileWebEndpointAutoConfiguration.java

+5-10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2019 the original author or authors.
2+
* Copyright 2012-2020 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.
@@ -56,16 +56,15 @@ public LogFileWebEndpoint logFileWebEndpoint(ObjectProvider<LogFile> logFile,
5656

5757
private static class LogFileCondition extends SpringBootCondition {
5858

59-
@SuppressWarnings("deprecation")
6059
@Override
6160
public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) {
6261
Environment environment = context.getEnvironment();
63-
String config = getLogFileConfig(environment, LogFile.FILE_NAME_PROPERTY, LogFile.FILE_PROPERTY);
62+
String config = getLogFileConfig(environment, LogFile.FILE_NAME_PROPERTY);
6463
ConditionMessage.Builder message = ConditionMessage.forCondition("Log File");
6564
if (StringUtils.hasText(config)) {
6665
return ConditionOutcome.match(message.found(LogFile.FILE_NAME_PROPERTY).items(config));
6766
}
68-
config = getLogFileConfig(environment, LogFile.FILE_PATH_PROPERTY, LogFile.PATH_PROPERTY);
67+
config = getLogFileConfig(environment, LogFile.FILE_PATH_PROPERTY);
6968
if (StringUtils.hasText(config)) {
7069
return ConditionOutcome.match(message.found(LogFile.FILE_PATH_PROPERTY).items(config));
7170
}
@@ -76,12 +75,8 @@ public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeM
7675
return ConditionOutcome.noMatch(message.didNotFind("logging file").atAll());
7776
}
7877

79-
private String getLogFileConfig(Environment environment, String configName, String deprecatedConfigName) {
80-
String config = environment.resolvePlaceholders("${" + configName + ":}");
81-
if (StringUtils.hasText(config)) {
82-
return config;
83-
}
84-
return environment.resolvePlaceholders("${" + deprecatedConfigName + ":}");
78+
private String getLogFileConfig(Environment environment, String configName) {
79+
return environment.resolvePlaceholders("${" + configName + ":}");
8580
}
8681

8782
}

Diff for: spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/logging/LogFileWebEndpointAutoConfigurationTests.java

+1-17
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2019 the original author or authors.
2+
* Copyright 2012-2020 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.
@@ -64,14 +64,6 @@ void runWhenLoggingFileIsSetAndExposedShouldHaveEndpointBean() {
6464
.run((context) -> assertThat(context).hasSingleBean(LogFileWebEndpoint.class));
6565
}
6666

67-
@Test
68-
@Deprecated
69-
void runWhenLoggingFileIsSetWithDeprecatedPropertyAndExposedShouldHaveEndpointBean() {
70-
this.contextRunner
71-
.withPropertyValues("logging.file:test.log", "management.endpoints.web.exposure.include=logfile")
72-
.run((context) -> assertThat(context).hasSingleBean(LogFileWebEndpoint.class));
73-
}
74-
7567
@Test
7668
void runWhenLoggingPathIsSetAndNotExposedShouldNotHaveEndpointBean() {
7769
this.contextRunner.withPropertyValues("logging.file.path:test/logs")
@@ -85,14 +77,6 @@ void runWhenLoggingPathIsSetAndExposedShouldHaveEndpointBean() {
8577
.run((context) -> assertThat(context).hasSingleBean(LogFileWebEndpoint.class));
8678
}
8779

88-
@Test
89-
@Deprecated
90-
void runWhenLoggingPathIsSetWithDeprecatedPropertyAndExposedShouldHaveEndpointBean() {
91-
this.contextRunner
92-
.withPropertyValues("logging.path:test/logs", "management.endpoints.web.exposure.include=logfile")
93-
.run((context) -> assertThat(context).hasSingleBean(LogFileWebEndpoint.class));
94-
}
95-
9680
@Test
9781
void logFileWebEndpointIsAutoConfiguredWhenExternalFileIsSet() {
9882
this.contextRunner

Diff for: spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/logging/LogFileWebEndpointTests.java

+1-11
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2019 the original author or authors.
2+
* Copyright 2012-2020 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.
@@ -74,16 +74,6 @@ void resourceResponseWithLogFile() throws Exception {
7474
assertThat(contentOf(resource.getFile())).isEqualTo("--TEST--");
7575
}
7676

77-
@Test
78-
@Deprecated
79-
void resourceResponseWithLogFileAndDeprecatedProperty() throws Exception {
80-
this.environment.setProperty("logging.file", this.logFile.getAbsolutePath());
81-
LogFileWebEndpoint endpoint = new LogFileWebEndpoint(LogFile.get(this.environment), null);
82-
Resource resource = endpoint.logFile();
83-
assertThat(resource).isNotNull();
84-
assertThat(contentOf(resource.getFile())).isEqualTo("--TEST--");
85-
}
86-
8777
@Test
8878
void resourceResponseWithExternalLogFile() throws Exception {
8979
LogFileWebEndpoint endpoint = new LogFileWebEndpoint(null, this.logFile);

Diff for: spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/logging/LogFileWebEndpointWebIntegrationTests.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2019 the original author or authors.
2+
* Copyright 2012-2020 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.
@@ -74,7 +74,7 @@ LogFileWebEndpoint logFileEndpoint() throws IOException {
7474
File logFile = new File(tempFile, "test.log");
7575
FileCopyUtils.copy("--TEST--".getBytes(), logFile);
7676
MockEnvironment environment = new MockEnvironment();
77-
environment.setProperty("logging.file", logFile.getAbsolutePath());
77+
environment.setProperty("logging.file.name", logFile.getAbsolutePath());
7878
return new LogFileWebEndpoint(LogFile.get(environment), null);
7979
}
8080

Diff for: spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/logging/LoggingApplicationListener.java

+2-36
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2019 the original author or authors.
2+
* Copyright 2012-2020 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.
@@ -136,13 +136,6 @@ public class LoggingApplicationListener implements GenericApplicationListener {
136136
*/
137137
public static final String LOGGER_GROUPS_BEAN_NAME = "springBootLoggerGroups";
138138

139-
/**
140-
* The name of the {@link LogFile} bean.
141-
* @deprecated since 2.2.0 in favor of {@link #LOG_FILE_BEAN_NAME}
142-
*/
143-
@Deprecated
144-
public static final String LOGFILE_BEAN_NAME = LOG_FILE_BEAN_NAME;
145-
146139
private static final Map<String, List<String>> DEFAULT_GROUP_LOGGERS;
147140
static {
148141
MultiValueMap<String, String> loggers = new LinkedMultiValueMap<>();
@@ -333,7 +326,7 @@ private boolean ignoreLogConfig(String logConfig) {
333326
private void initializeFinalLoggingLevels(ConfigurableEnvironment environment, LoggingSystem system) {
334327
bindLoggerGroups(environment);
335328
if (this.springBootLogging != null) {
336-
initializeLogLevel(system, this.springBootLogging);
329+
initializeSpringBootLogging(system, this.springBootLogging);
337330
}
338331
setLogLevels(system, environment);
339332
}
@@ -345,19 +338,6 @@ private void bindLoggerGroups(ConfigurableEnvironment environment) {
345338
}
346339
}
347340

348-
/**
349-
* Initialize loggers based on the {@link #setSpringBootLogging(LogLevel)
350-
* springBootLogging} setting.
351-
* @param system the logging system
352-
* @param springBootLogging the spring boot logging level requested
353-
* @deprecated since 2.2.0 in favor of
354-
* {@link #initializeSpringBootLogging(LoggingSystem, LogLevel)}
355-
*/
356-
@Deprecated
357-
protected void initializeLogLevel(LoggingSystem system, LogLevel springBootLogging) {
358-
initializeSpringBootLogging(system, springBootLogging);
359-
}
360-
361341
/**
362342
* Initialize loggers based on the {@link #setSpringBootLogging(LogLevel)
363343
* springBootLogging} setting. By default this implementation will pick an appropriate
@@ -372,20 +352,6 @@ protected void initializeSpringBootLogging(LoggingSystem system, LogLevel spring
372352
.forEach((name) -> configureLogLevel(name, springBootLogging, configurer));
373353
}
374354

375-
/**
376-
* Set logging levels based on relevant {@link Environment} properties.
377-
* @param system the logging system
378-
* @param environment the environment
379-
* @deprecated since 2.2.0 in favor of
380-
* {@link #setLogLevels(LoggingSystem, ConfigurableEnvironment)}
381-
*/
382-
@Deprecated
383-
protected void setLogLevels(LoggingSystem system, Environment environment) {
384-
if (environment instanceof ConfigurableEnvironment) {
385-
setLogLevels(system, (ConfigurableEnvironment) environment);
386-
}
387-
}
388-
389355
/**
390356
* Set logging levels based on relevant {@link Environment} properties.
391357
* @param system the logging system

Diff for: spring-boot-project/spring-boot/src/main/java/org/springframework/boot/logging/LogFile.java

+3-28
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2019 the original author or authors.
2+
* Copyright 2012-2020 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.
@@ -37,22 +37,6 @@
3737
*/
3838
public class LogFile {
3939

40-
/**
41-
* The name of the Spring property that contains the name of the log file. Names can
42-
* be an exact location or relative to the current directory.
43-
* @deprecated since 2.2.0 in favor of {@link #FILE_NAME_PROPERTY}
44-
*/
45-
@Deprecated
46-
public static final String FILE_PROPERTY = "logging.file";
47-
48-
/**
49-
* The name of the Spring property that contains the directory where log files are
50-
* written.
51-
* @deprecated since 2.2.0 in favor of {@link #FILE_PATH_PROPERTY}
52-
*/
53-
@Deprecated
54-
public static final String PATH_PROPERTY = "logging.path";
55-
5640
/**
5741
* The name of the Spring property that contains the name of the log file. Names can
5842
* be an exact location or relative to the current directory.
@@ -128,21 +112,12 @@ public String toString() {
128112
* suitable properties
129113
*/
130114
public static LogFile get(PropertyResolver propertyResolver) {
131-
String file = getLogFileProperty(propertyResolver, FILE_NAME_PROPERTY, FILE_PROPERTY);
132-
String path = getLogFileProperty(propertyResolver, FILE_PATH_PROPERTY, PATH_PROPERTY);
115+
String file = propertyResolver.getProperty(FILE_NAME_PROPERTY);
116+
String path = propertyResolver.getProperty(FILE_PATH_PROPERTY);
133117
if (StringUtils.hasLength(file) || StringUtils.hasLength(path)) {
134118
return new LogFile(file, path);
135119
}
136120
return null;
137121
}
138122

139-
private static String getLogFileProperty(PropertyResolver propertyResolver, String propertyName,
140-
String deprecatedPropertyName) {
141-
String property = propertyResolver.getProperty(propertyName);
142-
if (property != null) {
143-
return property;
144-
}
145-
return propertyResolver.getProperty(deprecatedPropertyName);
146-
}
147-
148123
}

Diff for: spring-boot-project/spring-boot/src/main/resources/META-INF/additional-spring-configuration-metadata.json

+4-2
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,8 @@
8585
"description": "Log file name (for instance, `myapp.log`). Names can be an exact location or relative to the current directory.",
8686
"sourceType": "org.springframework.boot.context.logging.LoggingApplicationListener",
8787
"deprecation": {
88-
"replacement": "logging.file.name"
88+
"replacement": "logging.file.name",
89+
"level": "error"
8990
}
9091
},
9192
{
@@ -146,7 +147,8 @@
146147
"description": "Location of the log file. For instance, `/var/log`.",
147148
"sourceType": "org.springframework.boot.context.logging.LoggingApplicationListener",
148149
"deprecation": {
149-
"replacement": "logging.file.path"
150+
"replacement": "logging.file.path",
151+
"level": "error"
150152
}
151153
},
152154
{

Diff for: spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/logging/LoggingApplicationListenerIntegrationTests.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2019 the original author or authors.
2+
* Copyright 2012-2020 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.
@@ -59,7 +59,7 @@ void loggingSystemRegisteredInTheContext() {
5959
void logFileRegisteredInTheContextWhenApplicable(@TempDir File tempDir) throws Exception {
6060
String logFile = new File(tempDir, "test.log").getAbsolutePath();
6161
try (ConfigurableApplicationContext context = new SpringApplicationBuilder(SampleService.class)
62-
.web(WebApplicationType.NONE).properties("logging.file=" + logFile).run()) {
62+
.web(WebApplicationType.NONE).properties("logging.file.name=" + logFile).run()) {
6363
SampleService service = context.getBean(SampleService.class);
6464
assertThat(service.logFile).isNotNull();
6565
assertThat(service.logFile.toString()).isEqualTo(logFile);

Diff for: spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/logging/LoggingApplicationListenerTests.java

+1-45
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2019 the original author or authors.
2+
* Copyright 2012-2020 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.
@@ -212,19 +212,6 @@ void addLogFileProperty() {
212212
assertThat(output).startsWith(this.logFile.getAbsolutePath());
213213
}
214214

215-
@Test
216-
@Deprecated
217-
void addLogFilePropertyWithDeprecatedProperty() {
218-
addPropertiesToEnvironment(this.context, "logging.config=classpath:logback-nondefault.xml",
219-
"logging.file=" + this.logFile);
220-
this.initializer.initialize(this.context.getEnvironment(), this.context.getClassLoader());
221-
Log logger = LogFactory.getLog(LoggingApplicationListenerTests.class);
222-
String existingOutput = this.output.toString();
223-
logger.info("Hello world");
224-
String output = this.output.toString().substring(existingOutput.length()).trim();
225-
assertThat(output).startsWith(this.logFile.getAbsolutePath());
226-
}
227-
228215
@Test
229216
void addLogFilePropertyWithDefault() {
230217
assertThat(this.logFile).doesNotExist();
@@ -235,16 +222,6 @@ void addLogFilePropertyWithDefault() {
235222
assertThat(this.logFile).isFile();
236223
}
237224

238-
@Test
239-
@Deprecated
240-
void addLogFilePropertyWithDefaultAndDeprecatedProperty() {
241-
addPropertiesToEnvironment(this.context, "logging.file=" + this.logFile);
242-
this.initializer.initialize(this.context.getEnvironment(), this.context.getClassLoader());
243-
Log logger = LogFactory.getLog(LoggingApplicationListenerTests.class);
244-
logger.info("Hello world");
245-
assertThat(this.logFile).isFile();
246-
}
247-
248225
@Test
249226
void addLogPathProperty() {
250227
addPropertiesToEnvironment(this.context, "logging.config=classpath:logback-nondefault.xml",
@@ -257,18 +234,6 @@ void addLogPathProperty() {
257234
assertThat(output).startsWith(new File(this.tempDir.toFile(), "spring.log").getAbsolutePath());
258235
}
259236

260-
@Test
261-
void addLogPathPropertyWithDeprecatedProperty() {
262-
addPropertiesToEnvironment(this.context, "logging.config=classpath:logback-nondefault.xml",
263-
"logging.path=" + this.tempDir);
264-
this.initializer.initialize(this.context.getEnvironment(), this.context.getClassLoader());
265-
Log logger = LogFactory.getLog(LoggingApplicationListenerTests.class);
266-
String existingOutput = this.output.toString();
267-
logger.info("Hello world");
268-
String output = this.output.toString().substring(existingOutput.length()).trim();
269-
assertThat(output).startsWith(new File(this.tempDir.toFile(), "spring.log").getAbsolutePath());
270-
}
271-
272237
@Test
273238
void parseDebugArg() {
274239
addPropertiesToEnvironment(this.context, "debug");
@@ -495,15 +460,6 @@ void systemPropertiesAreSetForLoggingConfiguration() {
495460
assertThat(System.getProperty(LoggingSystemProperties.PID_KEY)).isNotNull();
496461
}
497462

498-
@Test
499-
@Deprecated
500-
void systemPropertiesAreSetForLoggingConfigurationWithDeprecatedProperties() {
501-
addPropertiesToEnvironment(this.context, "logging.file=" + this.logFile, "logging.path=path");
502-
this.initializer.initialize(this.context.getEnvironment(), this.context.getClassLoader());
503-
assertThat(System.getProperty(LoggingSystemProperties.LOG_FILE)).isEqualTo(this.logFile.getAbsolutePath());
504-
assertThat(System.getProperty(LoggingSystemProperties.LOG_PATH)).isEqualTo("path");
505-
}
506-
507463
@Test
508464
void environmentPropertiesIgnoreUnresolvablePlaceholders() {
509465
// gh-7719

0 commit comments

Comments
 (0)