Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 975
Dims Avatar asked Aug 01 '16 10:08

Dims


People also ask

Where should Logback XML be stored?

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.

Which file is used by Logback logging system?

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.

What is logger name in Logback XML?

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.


1 Answers

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>
like image 106
xav Avatar answered Sep 21 '22 16:09

xav