Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2018 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.
Expand All @@ -23,6 +23,7 @@
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.SpringBootCondition;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.logging.LogFile;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ConditionContext;
import org.springframework.context.annotation.Conditional;
Expand All @@ -35,6 +36,7 @@
* {@link EnableAutoConfiguration Auto-configuration} for {@link LogFileWebEndpoint}.
*
* @author Andy Wilkinson
* @author Christian Carriere-Tisseur
* @since 2.0.0
*/
@Configuration
Expand All @@ -60,16 +62,25 @@ private static class LogFileCondition extends SpringBootCondition {
public ConditionOutcome getMatchOutcome(ConditionContext context,
AnnotatedTypeMetadata metadata) {
Environment environment = context.getEnvironment();
String config = environment.resolvePlaceholders("${logging.file.name:}");
String config = environment
.resolvePlaceholders("${" + LogFile.FILE_PROPERTY + ":}");
if (!StringUtils.hasText(config)) {
config = environment.resolvePlaceholders(
"${" + LogFile.DEPRECATED_FILE_PROPERTY + ":}");
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here I changed logging.file.name for LogFile.DEPRECATED_FILE_PROPERTY because that field is annotated with @Deprecated, which will make it easier to find and remove the deprecated code caused by this PR when the deprecation phase is over.

ConditionMessage.Builder message = ConditionMessage.forCondition("Log File");
if (StringUtils.hasText(config)) {
return ConditionOutcome
.match(message.found("logging.file.name").items(config));
.match(message.found(LogFile.FILE_PROPERTY).items(config));
}
config = environment.resolvePlaceholders("${" + LogFile.PATH_PROPERTY + ":}");
if (!StringUtils.hasText(config)) {
config = environment.resolvePlaceholders(
"${" + LogFile.DEPRECATED_PATH_PROPERTY + ":}");
}
config = environment.resolvePlaceholders("${logging.file.path:}");
if (StringUtils.hasText(config)) {
return ConditionOutcome
.match(message.found("logging.file.path").items(config));
.match(message.found(LogFile.PATH_PROPERTY).items(config));
}
config = environment.getProperty("management.endpoint.logfile.external-file");
if (StringUtils.hasText(config)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
* @author Andy Wilkinson
* @author Stephane Nicoll
* @author Phillip Webb
* @author Christian Carriere-Tisseur
*/
public class LogFileWebEndpointAutoConfigurationTests {

Expand All @@ -53,12 +54,26 @@ public void logFileWebEndpointIsAutoConfiguredWhenLoggingFileIsSet() {
(context) -> assertThat(context).hasSingleBean(LogFileWebEndpoint.class));
}

@Test
@Deprecated
public void logFileWebEndpointIsAutoConfiguredWhenLoggingFileIsSetWithDeprecatedProperty() {
this.contextRunner.withPropertyValues("logging.file:test.log").run(
(context) -> assertThat(context).hasSingleBean(LogFileWebEndpoint.class));
}

@Test
public void logFileWebEndpointIsAutoConfiguredWhenLoggingPathIsSet() {
this.contextRunner.withPropertyValues("logging.file.path:test/logs").run(
(context) -> assertThat(context).hasSingleBean(LogFileWebEndpoint.class));
}

@Test
@Deprecated
public void logFileWebEndpointIsAutoConfiguredWhenLoggingPathIsSetWithDeprecatedProperty() {
this.contextRunner.withPropertyValues("logging.path:test/logs").run(
(context) -> assertThat(context).hasSingleBean(LogFileWebEndpoint.class));
}

@Test
public void logFileWebEndpointIsAutoConfiguredWhenExternalFileIsSet() {
this.contextRunner
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
* written in the {@code logging.file.path} directory.
*
* @author Phillip Webb
* @author Christian Carriere-Tisseur
* @since 1.2.1
* @see #get(PropertyResolver)
*/
Expand Down