At the moment the configuration properties logging.file.name
and logging.file.path
will not expand the ~
character to the home directory, whether on Windows or Unix systems, and instead will create a directory named ~
.
It would be nice if Spring Boot could automatically expand the ~
character, which would allow for multi-platform configuration that relates to the user's home directory.
For instance when using H2, the spring.datasource.url
will correctly expand the ~
character.
I lodge this as a feature request since the documentation does not mention that path expansion is supported.
Comment From: wilkinsona
Configuration properties already support placeholder replacement in their values and any placeholder that matches a property in the environment will be replaced. The user.home
system property is part of the environment so you can use ${user.home}
to place a file within your home directory. For example logging.file.name=${user.home}/app.log
will result in the log file being written to ~/app.log
.
Comment From: gotson
It doesn't seem to be working with properties in yaml
though.
EDIT: My bad, it was conflicting with my gradle configuration:
withType<ProcessResources> {
filesMatching("application*.yml") {
expand(project.properties)
}
}
Comment From: wilkinsona
It should work with both .properties
and .yaml
files.
logging:
file:
name: ${user.home}/yaml.log
I've just double-checked and the YAML above results in the logs being written to ~/yaml.log
.
Comment From: gotson
@wilkinsona this is working indeed, however the syntax conflicts with the Groovy template for variable replacement of Gradle. This is complicating things, for example the above snippet is used in Gradle projects to replace the application version for Spring Boot to pickup:
application.version: ${version}
EDIT: after some quick googling, the Spring placeholder can be escaped, see here
All good then, thanks a lot everyone!