Skip to content

Commit 7939b8b

Browse files
committed
Polish "Rename logging.file to logging.file.name"
Closes gh-15089
1 parent 21da4a5 commit 7939b8b

File tree

9 files changed

+137
-113
lines changed

9 files changed

+137
-113
lines changed

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

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -58,27 +58,20 @@ public LogFileWebEndpoint logFileWebEndpoint(Environment environment) {
5858

5959
private static class LogFileCondition extends SpringBootCondition {
6060

61+
@SuppressWarnings("deprecation")
6162
@Override
6263
public ConditionOutcome getMatchOutcome(ConditionContext context,
6364
AnnotatedTypeMetadata metadata) {
6465
Environment environment = context.getEnvironment();
65-
String config = environment
66-
.resolvePlaceholders("${" + LogFile.FILE_NAME_PROPERTY + ":}");
67-
if (!StringUtils.hasText(config)) {
68-
config = environment
69-
.resolvePlaceholders("${" + LogFile.FILE_PROPERTY + ":}");
70-
}
66+
String config = getLogFileConfig(environment, LogFile.FILE_NAME_PROPERTY,
67+
LogFile.FILE_PROPERTY);
7168
ConditionMessage.Builder message = ConditionMessage.forCondition("Log File");
7269
if (StringUtils.hasText(config)) {
7370
return ConditionOutcome
7471
.match(message.found(LogFile.FILE_NAME_PROPERTY).items(config));
7572
}
76-
config = environment
77-
.resolvePlaceholders("${" + LogFile.FILE_PATH_PROPERTY + ":}");
78-
if (!StringUtils.hasText(config)) {
79-
config = environment
80-
.resolvePlaceholders("${" + LogFile.PATH_PROPERTY + ":}");
81-
}
73+
config = getLogFileConfig(environment, LogFile.FILE_PATH_PROPERTY,
74+
LogFile.PATH_PROPERTY);
8275
if (StringUtils.hasText(config)) {
8376
return ConditionOutcome
8477
.match(message.found(LogFile.FILE_PATH_PROPERTY).items(config));
@@ -92,6 +85,15 @@ public ConditionOutcome getMatchOutcome(ConditionContext context,
9285
return ConditionOutcome.noMatch(message.didNotFind("logging file").atAll());
9386
}
9487

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+
9597
}
9698

9799
}

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

Lines changed: 1 addition & 1 deletion
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.

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

Lines changed: 1 addition & 1 deletion
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.

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.name= # 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.file.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/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.name` or `logging.file.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/src/main/java/org/springframework/boot/logging/LogFile.java

Lines changed: 15 additions & 9 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.
@@ -131,19 +131,25 @@ public String toString() {
131131
* @return a {@link LogFile} or {@code null} if the environment didn't contain any
132132
* suitable properties
133133
*/
134+
@SuppressWarnings("deprecation")
134135
public static LogFile get(PropertyResolver propertyResolver) {
135-
String file = propertyResolver.getProperty(FILE_NAME_PROPERTY);
136-
String path = propertyResolver.getProperty(FILE_PATH_PROPERTY);
137-
if (file == null) {
138-
file = propertyResolver.getProperty(FILE_PROPERTY);
139-
}
140-
if (path == null) {
141-
path = propertyResolver.getProperty(PATH_PROPERTY);
142-
}
136+
String file = getLogFileProperty(propertyResolver, FILE_NAME_PROPERTY,
137+
FILE_PROPERTY);
138+
String path = getLogFileProperty(propertyResolver, FILE_PATH_PROPERTY,
139+
PATH_PROPERTY);
143140
if (StringUtils.hasLength(file) || StringUtils.hasLength(path)) {
144141
return new LogFile(file, path);
145142
}
146143
return null;
147144
}
148145

146+
private static String getLogFileProperty(PropertyResolver propertyResolver,
147+
String propertyName, String deprecatedPropertyName) {
148+
String property = propertyResolver.getProperty(propertyName);
149+
if (property != null) {
150+
return property;
151+
}
152+
return propertyResolver.getProperty(deprecatedPropertyName);
153+
}
154+
149155
}

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

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,15 @@
6767
"defaultValue": "%wEx",
6868
"sourceType": "org.springframework.boot.context.logging.LoggingApplicationListener"
6969
},
70+
{
71+
"name": "logging.file",
72+
"type": "java.lang.String",
73+
"description": "Log file name (for instance, `myapp.log`). Names can be an exact location or relative to the current directory.",
74+
"sourceType": "org.springframework.boot.context.logging.LoggingApplicationListener",
75+
"deprecation": {
76+
"replacement": "logging.file.name"
77+
}
78+
},
7079
{
7180
"name": "logging.file.name",
7281
"type": "java.lang.String",
@@ -105,6 +114,15 @@
105114
"description": "Log levels severity mapping. For instance, `logging.level.org.springframework=DEBUG`.",
106115
"sourceType": "org.springframework.boot.context.logging.LoggingApplicationListener"
107116
},
117+
{
118+
"name": "logging.path",
119+
"type": "java.lang.String",
120+
"description": "Location of the log file. For instance, `/var/log`.",
121+
"sourceType": "org.springframework.boot.context.logging.LoggingApplicationListener",
122+
"deprecation": {
123+
"replacement": "logging.file.path"
124+
}
125+
},
108126
{
109127
"name": "logging.pattern.console",
110128
"type": "java.lang.String",
@@ -332,28 +350,8 @@
332350
"type": "java.lang.Integer",
333351
"description": "Application index.",
334352
"deprecation": {
335-
"reason": "Application context ids are now unique by default.",
336-
"level": "error"
337-
}
338-
},
339-
{
340-
"name": "logging.file",
341-
"type": "java.lang.String",
342-
"description": "Log file name (for instance, `myapp.log`). Names can be an exact location or relative to the current directory.",
343-
"sourceType": "org.springframework.boot.context.logging.LoggingApplicationListener",
344-
"deprecation": {
345-
"replacement": "logging.file.name",
346-
"level": "error"
347-
}
348-
},
349-
{
350-
"name": "logging.path",
351-
"type": "java.lang.String",
352-
"description": "Location of the log file. For instance, `/var/log`.",
353-
"sourceType": "org.springframework.boot.context.logging.LoggingApplicationListener",
354-
"deprecation": {
355-
"replacement": "logging.file.path",
356-
"level": "error"
353+
"level": "error",
354+
"reason": "Application context ids are now unique by default."
357355
}
358356
}
359357
],
@@ -366,6 +364,7 @@
366364
"parameters": {
367365
"group": false
368366
}
367+
369368
}
370369
]
371370
},

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

Lines changed: 45 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,22 @@ public void addLogFileProperty() {
224224
assertThat(output).startsWith("target/foo.log");
225225
}
226226

227+
@Test
228+
@Deprecated
229+
public void addLogFilePropertyWithDeprecatedProperty() {
230+
TestPropertySourceUtils.addInlinedPropertiesToEnvironment(this.context,
231+
"logging.config=classpath:logback-nondefault.xml",
232+
"logging.file=target/foo.log");
233+
this.initializer.initialize(this.context.getEnvironment(),
234+
this.context.getClassLoader());
235+
Log logger = LogFactory.getLog(LoggingApplicationListenerTests.class);
236+
String existingOutput = this.outputCapture.toString();
237+
logger.info("Hello world");
238+
String output = this.outputCapture.toString().substring(existingOutput.length())
239+
.trim();
240+
assertThat(output).startsWith("target/foo.log");
241+
}
242+
227243
@Test
228244
public void addLogFilePropertyWithDefault() {
229245
assertThat(new File("target/foo.log").exists()).isFalse();
@@ -236,6 +252,19 @@ public void addLogFilePropertyWithDefault() {
236252
assertThat(new File("target/foo.log").exists()).isTrue();
237253
}
238254

255+
@Test
256+
@Deprecated
257+
public void addLogFilePropertyWithDefaultAndDeprecatedProperty() {
258+
assertThat(new File("target/foo.log").exists()).isFalse();
259+
TestPropertySourceUtils.addInlinedPropertiesToEnvironment(this.context,
260+
"logging.file=target/foo.log");
261+
this.initializer.initialize(this.context.getEnvironment(),
262+
this.context.getClassLoader());
263+
Log logger = LogFactory.getLog(LoggingApplicationListenerTests.class);
264+
logger.info("Hello world");
265+
assertThat(new File("target/foo.log").exists()).isTrue();
266+
}
267+
239268
@Test
240269
public void addLogPathProperty() {
241270
TestPropertySourceUtils.addInlinedPropertiesToEnvironment(this.context,
@@ -251,6 +280,21 @@ public void addLogPathProperty() {
251280
assertThat(output).startsWith("target/foo/spring.log");
252281
}
253282

283+
@Test
284+
public void addLogPathPropertyWithDeprecatedProperty() {
285+
TestPropertySourceUtils.addInlinedPropertiesToEnvironment(this.context,
286+
"logging.config=classpath:logback-nondefault.xml",
287+
"logging.path=target/foo/");
288+
this.initializer.initialize(this.context.getEnvironment(),
289+
this.context.getClassLoader());
290+
Log logger = LogFactory.getLog(LoggingApplicationListenerTests.class);
291+
String existingOutput = this.outputCapture.toString();
292+
logger.info("Hello world");
293+
String output = this.outputCapture.toString().substring(existingOutput.length())
294+
.trim();
295+
assertThat(output).startsWith("target/foo/spring.log");
296+
}
297+
254298
@Test
255299
public void parseDebugArg() {
256300
TestPropertySourceUtils.addInlinedPropertiesToEnvironment(this.context, "debug");
@@ -516,24 +560,13 @@ public void systemPropertiesAreSetForLoggingConfiguration() {
516560
@Deprecated
517561
public void systemPropertiesAreSetForLoggingConfigurationWithDeprecatedProperties() {
518562
TestPropertySourceUtils.addInlinedPropertiesToEnvironment(this.context,
519-
"logging.exception-conversion-word=conversion", "logging.file=target/log",
520-
"logging.path=path", "logging.pattern.console=console",
521-
"logging.pattern.file=file", "logging.pattern.level=level");
563+
"logging.file=target/log", "logging.path=path");
522564
this.initializer.initialize(this.context.getEnvironment(),
523565
this.context.getClassLoader());
524-
assertThat(System.getProperty(LoggingSystemProperties.CONSOLE_LOG_PATTERN))
525-
.isEqualTo("console");
526-
assertThat(System.getProperty(LoggingSystemProperties.FILE_LOG_PATTERN))
527-
.isEqualTo("file");
528-
assertThat(System.getProperty(LoggingSystemProperties.EXCEPTION_CONVERSION_WORD))
529-
.isEqualTo("conversion");
530566
assertThat(System.getProperty(LoggingSystemProperties.LOG_FILE))
531567
.isEqualTo("target/log");
532-
assertThat(System.getProperty(LoggingSystemProperties.LOG_LEVEL_PATTERN))
533-
.isEqualTo("level");
534568
assertThat(System.getProperty(LoggingSystemProperties.LOG_PATH))
535569
.isEqualTo("path");
536-
assertThat(System.getProperty(LoggingSystemProperties.PID_KEY)).isNotNull();
537570
}
538571

539572
@Test

0 commit comments

Comments
 (0)