In my Spring Boot configuration file, can I specify a logging file location relative to the Spring Boot jar instead of relative to the directory the jar is started from?
Example:
#application.yml
logging:
file: ./logs/app.log
Directories:
- /app/dir/app.jar
- /random/dir
Start:
cd /random/dir
java -jar /app/dir/app.jar
Result:
- /random/dir/logs/app.log
Desired:
- /app/dir/logs/app.log
Additional Info: The jar will be running on different operating systems. So the jar path could be similar to:
- /app/dir/app.jar
- C:\app\dir\app.jar
At run time, I can calculate what the jar/install directory is. Is there a Java solution that would allow me to set the logging.file location after startup? Or is the logger already initialized at that point?
Complete Solution: based on @satyesht
#application.yml
app:
log:
#Set a default directory in case a user "double clicks" the jar to launch it.
dir: ./logs
file: app.log
logging:
file: ${app.log.dir}/${app.log.file}
Start:
cd /random/dir
java -Dapp.log.dir=/app/dir/logs -jar /app/dir/app.jar