I would like to put log file into user home directory.
How to do that in portable way, i.e. working on Windows, Linux and Mac?
In a Spring Boot application, you can put the Logback. xml file in the resources folder. If your Logback. xml file is outside the classpath, you need to point to its location using the Logback.
To create a configuration for Logback, you can use XML as well as Groovy. The system will automatically pick up and use the configuration automatically, as long as you're adhering to the naming convention. There are three valid standard file names you can choose from: logback-test.
Logback Architecture A Logger is a context for log messages. This is the class that applications interact with to create log messages. Appenders place log messages in their final destinations. A Logger can have more than one Appender.
According to Logback documentation, you should use ${user.home}
, which is an environment variable present in the JVM directly coming from the OS (so it is portable):
<appender name="FILE" class="ch.qos.logback.core.FileAppender">
<file>${user.home}/logback.log</file>
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger - %msg%n</pattern>
</encoder>
</appender>
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