From 7031a3b17d14cee3ca8e09113f211bdf452ee798 Mon Sep 17 00:00:00 2001 From: Scott Frederick Date: Tue, 14 Jan 2020 13:02:38 -0600 Subject: [PATCH] Remove deprecated logging properties See gh-19699 --- .../LogFileWebEndpointAutoConfiguration.java | 15 ++---- ...FileWebEndpointAutoConfigurationTests.java | 18 +------- .../logging/LogFileWebEndpointTests.java | 12 +---- ...LogFileWebEndpointWebIntegrationTests.java | 4 +- .../logging/LoggingApplicationListener.java | 38 +-------------- .../springframework/boot/logging/LogFile.java | 31 ++----------- ...itional-spring-configuration-metadata.json | 6 ++- ...ngApplicationListenerIntegrationTests.java | 4 +- .../LoggingApplicationListenerTests.java | 46 +------------------ .../boot/logging/LogFileTests.java | 26 +---------- 10 files changed, 22 insertions(+), 178 deletions(-) diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/logging/LogFileWebEndpointAutoConfiguration.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/logging/LogFileWebEndpointAutoConfiguration.java index a86bea91e2..8de4be5b81 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/logging/LogFileWebEndpointAutoConfiguration.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/logging/LogFileWebEndpointAutoConfiguration.java @@ -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 + ":}"); } } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/logging/LogFileWebEndpointAutoConfigurationTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/logging/LogFileWebEndpointAutoConfigurationTests.java index acda4f0055..a7f5c0484c 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/logging/LogFileWebEndpointAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/logging/LogFileWebEndpointAutoConfigurationTests.java @@ -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 diff --git a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/logging/LogFileWebEndpointTests.java b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/logging/LogFileWebEndpointTests.java index 432256b55f..2e9139be15 100644 --- a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/logging/LogFileWebEndpointTests.java +++ b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/logging/LogFileWebEndpointTests.java @@ -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); diff --git a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/logging/LogFileWebEndpointWebIntegrationTests.java b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/logging/LogFileWebEndpointWebIntegrationTests.java index 3a0d2deaf2..702a759039 100644 --- a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/logging/LogFileWebEndpointWebIntegrationTests.java +++ b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/logging/LogFileWebEndpointWebIntegrationTests.java @@ -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); } diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/logging/LoggingApplicationListener.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/logging/LoggingApplicationListener.java index de5e762c4b..e6974e7d18 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/logging/LoggingApplicationListener.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/logging/LoggingApplicationListener.java @@ -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> DEFAULT_GROUP_LOGGERS; static { MultiValueMap 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 diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/logging/LogFile.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/logging/LogFile.java index 3ef1078bb9..b973bc9001 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/logging/LogFile.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/logging/LogFile.java @@ -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); - } - } diff --git a/spring-boot-project/spring-boot/src/main/resources/META-INF/additional-spring-configuration-metadata.json b/spring-boot-project/spring-boot/src/main/resources/META-INF/additional-spring-configuration-metadata.json index 02d488929e..5bbca0c280 100644 --- a/spring-boot-project/spring-boot/src/main/resources/META-INF/additional-spring-configuration-metadata.json +++ b/spring-boot-project/spring-boot/src/main/resources/META-INF/additional-spring-configuration-metadata.json @@ -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" } }, { diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/logging/LoggingApplicationListenerIntegrationTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/logging/LoggingApplicationListenerIntegrationTests.java index e88386364e..4f7e5eb341 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/logging/LoggingApplicationListenerIntegrationTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/logging/LoggingApplicationListenerIntegrationTests.java @@ -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); diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/logging/LoggingApplicationListenerTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/logging/LoggingApplicationListenerTests.java index 9701681107..ff25b3f77d 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/logging/LoggingApplicationListenerTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/logging/LoggingApplicationListenerTests.java @@ -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 diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/logging/LogFileTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/logging/LogFileTests.java index 0ec5b5d4fc..f2f952217c 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/logging/LogFileTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/logging/LogFileTests.java @@ -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 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();