How to put log file in user home directory in portable way in logback?

Dims picture Dims · Aug 1, 2016 · Viewed 8.2k times · Source

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?

Answer

xav picture xav · Aug 1, 2016

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>