Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting the user home path in application.properties in Spring Boot

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.

like image 944
shyam Avatar asked May 25 '15 06:05

shyam


People also ask

What is Spring Boot application properties?

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.

How to have spring active profile in application properties?

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.

How do I create a spring 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.

How do I create a Spring Boot application?

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.


2 Answers

${user.home} is your answer.

For example: ${user.home}/logs/app/app.log

Spring boot 2.2.6

like image 61
Adam Ostrožlík Avatar answered Sep 21 '22 16:09

Adam Ostrožlík


If you use Linux or Mac OS, you can use logging.path=${HOME}/logs.

${HOME} is substituted by the environment variable HOME.

like image 26
Chen H Avatar answered Sep 18 '22 16:09

Chen H