This should be a quite straight forward task, but after doing quite a bit of research I'm finding it hard to find any way to do this.
I just want to create a log file in the current user's home directory. According to the Official Documentation the variables I should modify are logging.file
and logging.path
. But how do I get the value of the user-home into the logging.path
?
I have tried setting it up like:
logging.path=#{systemProperties['user.home']}
but without any success.
How Spring boot application.properties works? As of now we already know that the application.properties file contains the property for the application which helps the application to run in the different environment if we have any.
Let us understand how to have Spring active profile in application.properties. By default, application. properties will be used to run the Spring Boot application. While running the JAR file, we need to specify the spring active profile based on each properties file. By default, Spring Boot application uses the application.properties file.
Spring Boot loads the application.properties file automatically from the project classpath. All you have to do is to create a new file under the src/main/resources directory. The application.properties file is just a regular text file. Each line contains a property key, the equals sign, and a value of the property.
Spring Boot loads the application.properties file automatically from the project classpath. All you have to do is to create a new file under the src/main/resources directory. The application.properties file is just a regular text file. Each line contains a property key, the equals sign, and a value of the property. Blank lines are also allowed.
${user.home}
is your answer.
For example: ${user.home}/logs/app/app.log
Spring boot 2.2.6
If you use Linux or Mac OS, you can use logging.path=${HOME}/logs
.
${HOME}
is substituted by the environment variable HOME
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With