Skip to content
Closed
Show file tree
Hide file tree
Changes from 6 commits
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
Expand Up @@ -60,16 +60,16 @@ private static class LogFileCondition extends SpringBootCondition {
public ConditionOutcome getMatchOutcome(ConditionContext context,
AnnotatedTypeMetadata metadata) {
Environment environment = context.getEnvironment();
String config = environment.resolvePlaceholders("${logging.file:}");
String config = environment.resolvePlaceholders("${logging.file.name:}");
ConditionMessage.Builder message = ConditionMessage.forCondition("Log File");
if (StringUtils.hasText(config)) {
return ConditionOutcome
.match(message.found("logging.file").items(config));
.match(message.found("logging.file.name").items(config));
}
config = environment.resolvePlaceholders("${logging.path:}");
config = environment.resolvePlaceholders("${logging.file.path:}");
if (StringUtils.hasText(config)) {
return ConditionOutcome
.match(message.found("logging.path").items(config));
.match(message.found("logging.file.path").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 @@ -34,7 +34,7 @@
*
* @author Andy Wilkinson
*/
@TestPropertySource(properties = "logging.file=src/test/resources/org/springframework/boot/actuate/autoconfigure/endpoint/web/documentation/sample.log")
@TestPropertySource(properties = "logging.file.name=src/test/resources/org/springframework/boot/actuate/autoconfigure/endpoint/web/documentation/sample.log")
public class LogFileWebEndpointDocumentationTests
extends MockMvcEndpointDocumentationTests {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,13 @@ public class LogFileWebEndpointAutoConfigurationTests {

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

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

Expand All @@ -71,7 +71,7 @@ public void logFileWebEndpointIsAutoConfiguredWhenExternalFileIsSet() {
@Test
public void logFileWebEndpointCanBeDisabled() {
this.contextRunner
.withPropertyValues("logging.file:test.log",
.withPropertyValues("logging.file.name:test.log",
"management.endpoint.logfile.enabled:false")
.run((context) -> assertThat(context)
.hasSingleBean(LogFileWebEndpoint.class));
Expand Down
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 Down Expand Up @@ -70,7 +70,7 @@ private Resource getLogFileResource() {
}
LogFile logFile = LogFile.get(this.environment);
if (logFile == null) {
logger.debug("Missing 'logging.file' or 'logging.path' properties");
logger.debug("Missing 'logging.file.name' or 'logging.file.path' properties");
return null;
}
return new FileSystemResource(logFile.toString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,13 @@ public void nullResponseWithoutLogFile() {

@Test
public void nullResponseWithMissingLogFile() {
this.environment.setProperty("logging.file", "no_test.log");
this.environment.setProperty("logging.file.name", "no_test.log");
assertThat(this.endpoint.logFile()).isNull();
}

@Test
public void resourceResponseWithLogFile() throws Exception {
this.environment.setProperty("logging.file", this.logFile.getAbsolutePath());
this.environment.setProperty("logging.file.name", this.logFile.getAbsolutePath());
Resource resource = this.endpoint.logFile();
assertThat(resource).isNotNull();
assertThat(StreamUtils.copyToString(resource.getInputStream(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public void getRequestProduces404ResponseWhenLogFileNotFound() {

@Test
public void getRequestProducesResponseWithLogFile() {
TestPropertyValues.of("logging.file:" + this.logFile.getAbsolutePath())
TestPropertyValues.of("logging.file.name:" + this.logFile.getAbsolutePath())
.applyTo(context);
client.get().uri("/actuator/logfile").exchange().expectStatus().isOk()
.expectBody(String.class).isEqualTo("--TEST--");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ content into your application. Rather, pick only the properties that you need.
# LOGGING
logging.config= # Location of the logging configuration file. For instance, `classpath:logback.xml` for Logback.
logging.exception-conversion-word=%wEx # Conversion word used when logging exceptions.
logging.file= # Log file name (for instance, `myapp.log`). Names can be an exact location or relative to the current directory.
logging.file.name= # Log file name (for instance, `myapp.log`). Names can be an exact location or relative to the current directory.
logging.file.max-history=0 # Maximum of archive log files to keep. Only supported with the default logback setup.
logging.file.max-size=10MB # Maximum log file size. Only supported with the default logback setup.
logging.group.*= # Log groups to quickly change multiple loggers at the same time. For instance, `logging.level.db=org.hibernate,org.springframework.jdbc`.
logging.level.*= # Log levels severity mapping. For instance, `logging.level.org.springframework=DEBUG`.
logging.path= # Location of the log file. For instance, `/var/log`.
logging.file.path= # Location of the log file. For instance, `/var/log`.
logging.pattern.console= # Appender pattern for output to the console. Supported only with the default Logback setup.
logging.pattern.dateformat=yyyy-MM-dd HH:mm:ss.SSS # Appender pattern for log date format. Supported only with the default Logback setup.
logging.pattern.file= # Appender pattern for output to a file. Supported only with the default Logback setup.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1531,7 +1531,7 @@ in the following example:
----

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

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

* `${PID}`: The current process ID.
* `${LOG_FILE}`: Whether `logging.file` was set in Boot's external configuration.
* `${LOG_PATH}`: Whether `logging.path` (representing a directory for
* `${LOG_FILE}`: Whether `logging.file.name` was set in Boot's external configuration.
* `${LOG_PATH}`: Whether `logging.file.path` (representing a directory for
log files to live in) was set in Boot's external configuration.
* `${LOG_EXCEPTION_CONVERSION_WORD}`: Whether `logging.exception-conversion-word` was set
in Boot's external configuration.
Expand Down Expand Up @@ -1595,12 +1595,12 @@ shown in the following example:
</configuration>
----

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

[source,properties,indent=0,subs="verbatim,quotes,attributes"]
----
logging.file=myapplication.log
logging.file.name=myapplication.log
----


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ use the following additional endpoints:
|Yes

|`logfile`
|Returns the contents of the logfile (if `logging.file` or `logging.path` properties have
|Returns the contents of the logfile (if `logging.file.name` or `logging.file.path` properties have
been set). Supports the use of the HTTP `Range` header to retrieve part of the log file's
content.
|Yes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1686,15 +1686,15 @@ The following colors and styles are supported:
=== File Output
By default, Spring Boot logs only to the console and does not write log files. If you
want to write log files in addition to the console output, you need to set a
`logging.file` or `logging.path` property (for example, in your
`logging.file.name` or `logging.file.path` property (for example, in your
`application.properties`).

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

.Logging properties
[cols="1,1,1,4"]
|===
|`logging.file` |`logging.path` |Example |Description
|`logging.file.name` |`logging.file.path` |Example |Description

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

|`logging.file`
|`logging.file.name`
|`LOG_FILE`
|If defined, it is used in the default log configuration.

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

|`logging.path`
|`logging.file.path`
|`LOG_PATH`
|If defined, it is used in the default log configuration.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@
* {@literal java -jar myapp.jar [--debug | --trace]}). If you prefer to ignore these
* properties you can set {@link #setParseArgs(boolean) parseArgs} to {@code false}.
* <p>
* By default, log output is only written to the console. If a log file is required the
* {@code logging.path} and {@code logging.file} properties can be used.
* By default, log output is only written to the console. If a log file is required, the
* {@code logging.file.path} and {@code logging.file.name} properties can be used.
* <p>
* Some system properties may be set as side effects, and these can be useful if the
* logging configuration supports placeholders (i.e. log4j or logback):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@

/**
* A reference to a log output file. Log output files are specified using
* {@code logging.file} or {@code logging.path} {@link Environment} properties. If the
* {@code logging.file} property is not specified {@code "spring.log"} will be written in
* the {@code logging.path} directory.
* {@code logging.file.name} or {@code logging.file.path} {@link Environment} properties.
* If the {@code logging.file.name} property is not specified {@code "spring.log"} will be
* written in the {@code logging.file.path} directory.
*
* @author Phillip Webb
* @since 1.2.1
Expand All @@ -39,13 +39,13 @@ 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.
*/
public static final String FILE_PROPERTY = "logging.file";
public static final String FILE_PROPERTY = "logging.file.name";

/**
* The name of the Spring property that contains the directory where log files are
* written.
*/
public static final String PATH_PROPERTY = "logging.path";
public static final String PATH_PROPERTY = "logging.file.path";

private final String file;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,36 @@
"defaultValue": "%wEx",
"sourceType": "org.springframework.boot.context.logging.LoggingApplicationListener"
},
{
"name": "logging.file.name",
"type": "java.lang.String",
"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"
},
{
"name": "logging.file",
"type": "java.lang.String",
"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"
}
},
{
"name": "logging.file.path",
"type": "java.lang.String",
"description": "Location of the log file. For instance, `/var/log`.",
"sourceType": "org.springframework.boot.context.logging.LoggingApplicationListener"
},
{
"name": "logging.path",
"type": "java.lang.String",
"description": "Location of the log file. For instance, `/var/log`.",
"sourceType": "org.springframework.boot.context.logging.LoggingApplicationListener",
"deprecation": {
"replacement": "logging.file.path"
}
},
{
"name": "logging.file.max-size",
"type": "java.lang.String",
Expand All @@ -99,12 +123,6 @@
"description": "Log levels severity mapping. For instance, `logging.level.org.springframework=DEBUG`.",
"sourceType": "org.springframework.boot.context.logging.LoggingApplicationListener"
},
{
"name": "logging.path",
"type": "java.lang.String",
"description": "Location of the log file. For instance, `/var/log`.",
"sourceType": "org.springframework.boot.context.logging.LoggingApplicationListener"
},
{
"name": "logging.pattern.console",
"type": "java.lang.String",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,13 @@ public void propertiesAsProperties() {
public void propertiesWithRepeatSeparator() {
SpringApplicationBuilder application = new SpringApplicationBuilder()
.sources(ExampleConfig.class).contextClass(StaticApplicationContext.class)
.properties("one=c:\\logging.file", "two=a:b", "three:c:\\logging.file",
"four:a:b");
.properties("one=c:\\logging.file.name", "two=a:b",
"three:c:\\logging.file.name", "four:a:b");
this.context = application.run();
ConfigurableEnvironment environment = this.context.getEnvironment();
assertThat(environment.getProperty("one")).isEqualTo("c:\\logging.file");
assertThat(environment.getProperty("one")).isEqualTo("c:\\logging.file.name");
assertThat(environment.getProperty("two")).isEqualTo("a:b");
assertThat(environment.getProperty("three")).isEqualTo("c:\\logging.file");
assertThat(environment.getProperty("three")).isEqualTo("c:\\logging.file.name");
assertThat(environment.getProperty("four")).isEqualTo("a:b");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ public void overrideConfigBroken() {
public void addLogFileProperty() {
TestPropertySourceUtils.addInlinedPropertiesToEnvironment(this.context,
"logging.config=classpath:logback-nondefault.xml",
"logging.file=target/foo.log");
"logging.file.name=target/foo.log");
this.initializer.initialize(this.context.getEnvironment(),
this.context.getClassLoader());
Log logger = LogFactory.getLog(LoggingApplicationListenerTests.class);
Expand All @@ -228,7 +228,7 @@ public void addLogFileProperty() {
public void addLogFilePropertyWithDefault() {
assertThat(new File("target/foo.log").exists()).isFalse();
TestPropertySourceUtils.addInlinedPropertiesToEnvironment(this.context,
"logging.file=target/foo.log");
"logging.file.name=target/foo.log");
this.initializer.initialize(this.context.getEnvironment(),
this.context.getClassLoader());
Log logger = LogFactory.getLog(LoggingApplicationListenerTests.class);
Expand All @@ -240,7 +240,7 @@ public void addLogFilePropertyWithDefault() {
public void addLogPathProperty() {
TestPropertySourceUtils.addInlinedPropertiesToEnvironment(this.context,
"logging.config=classpath:logback-nondefault.xml",
"logging.path=target/foo/");
"logging.file.path=target/foo/");
this.initializer.initialize(this.context.getEnvironment(),
this.context.getClassLoader());
Log logger = LogFactory.getLog(LoggingApplicationListenerTests.class);
Expand Down Expand Up @@ -479,9 +479,10 @@ public void closingChildContextDoesNotCleanUpLoggingSystem() {
@Test
public void systemPropertiesAreSetForLoggingConfiguration() {
TestPropertySourceUtils.addInlinedPropertiesToEnvironment(this.context,
"logging.exception-conversion-word=conversion", "logging.file=target/log",
"logging.path=path", "logging.pattern.console=console",
"logging.pattern.file=file", "logging.pattern.level=level");
"logging.exception-conversion-word=conversion",
"logging.file.name=target/log", "logging.file.path=path",
"logging.pattern.console=console", "logging.pattern.file=file",
"logging.pattern.level=level");
this.initializer.initialize(this.context.getEnvironment(),
this.context.getClassLoader());
assertThat(System.getProperty(LoggingSystemProperties.CONSOLE_LOG_PATTERN))
Expand Down Expand Up @@ -524,7 +525,7 @@ public void environmentPropertiesResolvePlaceholders() {
@Test
public void logFilePropertiesCanReferenceSystemProperties() {
TestPropertySourceUtils.addInlinedPropertiesToEnvironment(this.context,
"logging.file=target/${PID}.log");
"logging.file.name=target/${PID}.log");
this.initializer.initialize(this.context.getEnvironment(),
this.context.getClassLoader());
assertThat(System.getProperty(LoggingSystemProperties.LOG_FILE))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ public void loggingFileAndPath() {

private PropertyResolver getPropertyResolver(String file, String path) {
Map<String, Object> properties = new LinkedHashMap<>();
properties.put("logging.file", file);
properties.put("logging.path", path);
properties.put("logging.file.name", file);
properties.put("logging.file.path", path);
PropertySource<?> propertySource = new MapPropertySource("properties",
properties);
MutablePropertySources propertySources = new MutablePropertySources();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ service.name=Phil
spring.security.user.name=user
spring.security.user.password=password

# logging.file=/tmp/logs/app.log
# logging.file.name=/tmp/logs/app.log
# logging.level.org.springframework.security=DEBUG
management.server.address=127.0.0.1

Expand Down