Skip to content

Commit 389ab95

Browse files
committed
Merge pull request #15089 from TwinProduction
* pr/15089: Polish "Rename logging.file to logging.file.name" Rename logging.file to logging.file.name
2 parents 56ae9cf + 7939b8b commit 389ab95

File tree

17 files changed

+241
-54
lines changed

17 files changed

+241
-54
lines changed

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

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2017 the original author or authors.
2+
* Copyright 2012-2018 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.
@@ -23,6 +23,7 @@
2323
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
2424
import org.springframework.boot.autoconfigure.condition.SpringBootCondition;
2525
import org.springframework.boot.context.properties.EnableConfigurationProperties;
26+
import org.springframework.boot.logging.LogFile;
2627
import org.springframework.context.annotation.Bean;
2728
import org.springframework.context.annotation.ConditionContext;
2829
import org.springframework.context.annotation.Conditional;
@@ -35,6 +36,7 @@
3536
* {@link EnableAutoConfiguration Auto-configuration} for {@link LogFileWebEndpoint}.
3637
*
3738
* @author Andy Wilkinson
39+
* @author Christian Carriere-Tisseur
3840
* @since 2.0.0
3941
*/
4042
@Configuration
@@ -56,20 +58,23 @@ public LogFileWebEndpoint logFileWebEndpoint(Environment environment) {
5658

5759
private static class LogFileCondition extends SpringBootCondition {
5860

61+
@SuppressWarnings("deprecation")
5962
@Override
6063
public ConditionOutcome getMatchOutcome(ConditionContext context,
6164
AnnotatedTypeMetadata metadata) {
6265
Environment environment = context.getEnvironment();
63-
String config = environment.resolvePlaceholders("${logging.file:}");
66+
String config = getLogFileConfig(environment, LogFile.FILE_NAME_PROPERTY,
67+
LogFile.FILE_PROPERTY);
6468
ConditionMessage.Builder message = ConditionMessage.forCondition("Log File");
6569
if (StringUtils.hasText(config)) {
6670
return ConditionOutcome
67-
.match(message.found("logging.file").items(config));
71+
.match(message.found(LogFile.FILE_NAME_PROPERTY).items(config));
6872
}
69-
config = environment.resolvePlaceholders("${logging.path:}");
73+
config = getLogFileConfig(environment, LogFile.FILE_PATH_PROPERTY,
74+
LogFile.PATH_PROPERTY);
7075
if (StringUtils.hasText(config)) {
7176
return ConditionOutcome
72-
.match(message.found("logging.path").items(config));
77+
.match(message.found(LogFile.FILE_PATH_PROPERTY).items(config));
7378
}
7479
config = environment.getProperty("management.endpoint.logfile.external-file");
7580
if (StringUtils.hasText(config)) {
@@ -80,6 +85,15 @@ public ConditionOutcome getMatchOutcome(ConditionContext context,
8085
return ConditionOutcome.noMatch(message.didNotFind("logging file").atAll());
8186
}
8287

88+
private String getLogFileConfig(Environment environment, String configName,
89+
String deprecatedConfigName) {
90+
String config = environment.resolvePlaceholders("${" + configName + ":}");
91+
if (StringUtils.hasText(config)) {
92+
return config;
93+
}
94+
return environment.resolvePlaceholders("${" + deprecatedConfigName + ":}");
95+
}
96+
8397
}
8498

8599
}

spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/endpoint/web/documentation/LogFileWebEndpointDocumentationTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
*
3535
* @author Andy Wilkinson
3636
*/
37-
@TestPropertySource(properties = "logging.file=src/test/resources/org/springframework/boot/actuate/autoconfigure/endpoint/web/documentation/sample.log")
37+
@TestPropertySource(properties = "logging.file.name=src/test/resources/org/springframework/boot/actuate/autoconfigure/endpoint/web/documentation/sample.log")
3838
public class LogFileWebEndpointDocumentationTests
3939
extends MockMvcEndpointDocumentationTests {
4040

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

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
* @author Andy Wilkinson
3939
* @author Stephane Nicoll
4040
* @author Phillip Webb
41+
* @author Christian Carriere-Tisseur
4142
*/
4243
public class LogFileWebEndpointAutoConfigurationTests {
4344

@@ -49,12 +50,26 @@ public class LogFileWebEndpointAutoConfigurationTests {
4950

5051
@Test
5152
public void logFileWebEndpointIsAutoConfiguredWhenLoggingFileIsSet() {
53+
this.contextRunner.withPropertyValues("logging.file.name:test.log").run(
54+
(context) -> assertThat(context).hasSingleBean(LogFileWebEndpoint.class));
55+
}
56+
57+
@Test
58+
@Deprecated
59+
public void logFileWebEndpointIsAutoConfiguredWhenLoggingFileIsSetWithDeprecatedProperty() {
5260
this.contextRunner.withPropertyValues("logging.file:test.log").run(
5361
(context) -> assertThat(context).hasSingleBean(LogFileWebEndpoint.class));
5462
}
5563

5664
@Test
5765
public void logFileWebEndpointIsAutoConfiguredWhenLoggingPathIsSet() {
66+
this.contextRunner.withPropertyValues("logging.file.path:test/logs").run(
67+
(context) -> assertThat(context).hasSingleBean(LogFileWebEndpoint.class));
68+
}
69+
70+
@Test
71+
@Deprecated
72+
public void logFileWebEndpointIsAutoConfiguredWhenLoggingPathIsSetWithDeprecatedProperty() {
5873
this.contextRunner.withPropertyValues("logging.path:test/logs").run(
5974
(context) -> assertThat(context).hasSingleBean(LogFileWebEndpoint.class));
6075
}
@@ -71,7 +86,7 @@ public void logFileWebEndpointIsAutoConfiguredWhenExternalFileIsSet() {
7186
@Test
7287
public void logFileWebEndpointCanBeDisabled() {
7388
this.contextRunner
74-
.withPropertyValues("logging.file:test.log",
89+
.withPropertyValues("logging.file.name:test.log",
7590
"management.endpoint.logfile.enabled:false")
7691
.run((context) -> assertThat(context)
7792
.hasSingleBean(LogFileWebEndpoint.class));

spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/logging/LogFileWebEndpoint.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2017 the original author or authors.
2+
* Copyright 2012-2018 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.
@@ -70,7 +70,7 @@ private Resource getLogFileResource() {
7070
}
7171
LogFile logFile = LogFile.get(this.environment);
7272
if (logFile == null) {
73-
logger.debug("Missing 'logging.file' or 'logging.path' properties");
73+
logger.debug("Missing 'logging.file.name' or 'logging.file.path' properties");
7474
return null;
7575
}
7676
return new FileSystemResource(logFile.toString());

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2017 the original author or authors.
2+
* Copyright 2012-2018 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.
@@ -63,12 +63,22 @@ public void nullResponseWithoutLogFile() {
6363

6464
@Test
6565
public void nullResponseWithMissingLogFile() {
66-
this.environment.setProperty("logging.file", "no_test.log");
66+
this.environment.setProperty("logging.file.name", "no_test.log");
6767
assertThat(this.endpoint.logFile()).isNull();
6868
}
6969

7070
@Test
7171
public void resourceResponseWithLogFile() throws Exception {
72+
this.environment.setProperty("logging.file.name", this.logFile.getAbsolutePath());
73+
Resource resource = this.endpoint.logFile();
74+
assertThat(resource).isNotNull();
75+
assertThat(StreamUtils.copyToString(resource.getInputStream(),
76+
StandardCharsets.UTF_8)).isEqualTo("--TEST--");
77+
}
78+
79+
@Test
80+
@Deprecated
81+
public void resourceResponseWithLogFileAndDeprecatedProperty() throws Exception {
7282
this.environment.setProperty("logging.file", this.logFile.getAbsolutePath());
7383
Resource resource = this.endpoint.logFile();
7484
assertThat(resource).isNotNull();

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2017 the original author or authors.
2+
* Copyright 2012-2018 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.
@@ -65,7 +65,7 @@ public void getRequestProduces404ResponseWhenLogFileNotFound() {
6565

6666
@Test
6767
public void getRequestProducesResponseWithLogFile() {
68-
TestPropertyValues.of("logging.file:" + this.logFile.getAbsolutePath())
68+
TestPropertyValues.of("logging.file.name:" + this.logFile.getAbsolutePath())
6969
.applyTo(context);
7070
client.get().uri("/actuator/logfile").exchange().expectStatus().isOk()
7171
.expectBody(String.class).isEqualTo("--TEST--");

spring-boot-project/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,12 @@ content into your application. Rather, pick only the properties that you need.
3737
# LOGGING
3838
logging.config= # Location of the logging configuration file. For instance, `classpath:logback.xml` for Logback.
3939
logging.exception-conversion-word=%wEx # Conversion word used when logging exceptions.
40-
logging.file= # Log file name (for instance, `myapp.log`). Names can be an exact location or relative to the current directory.
4140
logging.file.max-history=0 # Maximum of archive log files to keep. Only supported with the default logback setup.
4241
logging.file.max-size=10MB # Maximum log file size. Only supported with the default logback setup.
42+
logging.file.name= # Log file name (for instance, `myapp.log`). Names can be an exact location or relative to the current directory.
43+
logging.file.path= # Location of the log file. For instance, `/var/log`.
4344
logging.group.*= # Log groups to quickly change multiple loggers at the same time. For instance, `logging.level.db=org.hibernate,org.springframework.jdbc`.
4445
logging.level.*= # Log levels severity mapping. For instance, `logging.level.org.springframework=DEBUG`.
45-
logging.path= # Location of the log file. For instance, `/var/log`.
4646
logging.pattern.console= # Appender pattern for output to the console. Supported only with the default Logback setup.
4747
logging.pattern.dateformat=yyyy-MM-dd HH:mm:ss.SSS # Appender pattern for log date format. Supported only with the default Logback setup.
4848
logging.pattern.file= # Appender pattern for output to a file. Supported only with the default Logback setup.

spring-boot-project/spring-boot-docs/src/main/asciidoc/howto.adoc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1518,7 +1518,7 @@ in the following example:
15181518
----
15191519

15201520
You can also set the location of a file to which to write the log (in addition to the
1521-
console) by using "logging.file".
1521+
console) by using "logging.file.name".
15221522

15231523
To configure the more fine-grained settings of a logging system, you need to use the native
15241524
configuration format supported by the `LoggingSystem` in question. By default, Spring Boot
@@ -1548,8 +1548,8 @@ If you look at `base.xml` in the spring-boot jar, you can see that it uses
15481548
some useful System properties that the `LoggingSystem` takes care of creating for you:
15491549

15501550
* `${PID}`: The current process ID.
1551-
* `${LOG_FILE}`: Whether `logging.file` was set in Boot's external configuration.
1552-
* `${LOG_PATH}`: Whether `logging.path` (representing a directory for
1551+
* `${LOG_FILE}`: Whether `logging.file.name` was set in Boot's external configuration.
1552+
* `${LOG_PATH}`: Whether `logging.file.path` (representing a directory for
15531553
log files to live in) was set in Boot's external configuration.
15541554
* `${LOG_EXCEPTION_CONVERSION_WORD}`: Whether `logging.exception-conversion-word` was set
15551555
in Boot's external configuration.
@@ -1582,12 +1582,12 @@ shown in the following example:
15821582
</configuration>
15831583
----
15841584

1585-
You also need to add `logging.file` to your `application.properties`, as shown in the
1585+
You also need to add `logging.file.name` to your `application.properties`, as shown in the
15861586
following example:
15871587

15881588
[source,properties,indent=0,subs="verbatim,quotes,attributes"]
15891589
----
1590-
logging.file=myapplication.log
1590+
logging.file.name=myapplication.log
15911591
----
15921592

15931593

spring-boot-project/spring-boot-docs/src/main/asciidoc/production-ready-features.adoc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,9 +164,9 @@ use the following additional endpoints:
164164
|Yes
165165

166166
|`logfile`
167-
|Returns the contents of the logfile (if `logging.file` or `logging.path` properties have
168-
been set). Supports the use of the HTTP `Range` header to retrieve part of the log file's
169-
content.
167+
|Returns the contents of the logfile (if `logging.file.name` or `logging.file.path`
168+
properties have been set). Supports the use of the HTTP `Range` header to retrieve part of
169+
the log file's content.
170170
|Yes
171171

172172
|`prometheus`

spring-boot-project/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1686,15 +1686,15 @@ The following colors and styles are supported:
16861686
=== File Output
16871687
By default, Spring Boot logs only to the console and does not write log files. If you
16881688
want to write log files in addition to the console output, you need to set a
1689-
`logging.file` or `logging.path` property (for example, in your
1689+
`logging.file.name` or `logging.file.path` property (for example, in your
16901690
`application.properties`).
16911691

16921692
The following table shows how the `logging.*` properties can be used together:
16931693

16941694
.Logging properties
16951695
[cols="1,1,1,4"]
16961696
|===
1697-
|`logging.file` |`logging.path` |Example |Description
1697+
|`logging.file.name` |`logging.file.path` |Example |Description
16981698

16991699
|_(none)_
17001700
|_(none)_
@@ -1835,7 +1835,7 @@ To help with the customization, some other properties are transferred from the S
18351835
|`LOG_EXCEPTION_CONVERSION_WORD`
18361836
|The conversion word used when logging exceptions.
18371837

1838-
|`logging.file`
1838+
|`logging.file.name`
18391839
|`LOG_FILE`
18401840
|If defined, it is used in the default log configuration.
18411841

@@ -1849,7 +1849,7 @@ setup.)
18491849
|Maximum number of archive log files to keep (if LOG_FILE enabled). (Only supported with
18501850
the default Logback setup.)
18511851

1852-
|`logging.path`
1852+
|`logging.file.path`
18531853
|`LOG_PATH`
18541854
|If defined, it is used in the default log configuration.
18551855

0 commit comments

Comments
 (0)