How to put the log file in the user's home directory in portable mode in the log?

I would like to put the log file in the user's home directory.

How to do it in a portable way, i.e. work with Windows, Linux and Mac?

+4
source share
2 answers

According to the documentation for the protocol , you should use ${user.home}, which is the environment variable present in the JVM, directly coming from the OS (so it is transferred):

<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>
+9
source

- . ( ) . - - Apache Commons, , , .

"" . Apache Commons, :

<configuration config-name="master-config">
<!--  start here, properties encountered in the first file would be ignored in the last file -->
<properties fileName="/opt/config/log.properties" optional="true"/> 
<properties fileName="${sys:user.home}/config/product/log.properties" optional="true"/>
<properties fileName="com/company/product/config/log.properties"/>    

( ${sys: user.home}/config/product/log.properties)

logbackConfigLocation=C:/Users/dan/config/product/logback.xml 

/ / . .

0

Source: https://habr.com/ru/post/1649773/


All Articles