Setting up for RollingFileAppender backup with forward-looking flag and file location

How can I break RollingFileAppender

in Logback that accepts the prudent flag and also allows me to determine the location of the log files?

I tried the following, but as I understand from the documentation log it doesn't support the file property. Is there any other way to set the location of the log file?

   <appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <file>${MY_LOG_LOCATION_PROP}/logs/mylogfile.log</file>
        <prudent>true</prudent>
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <!-- rollover daily -->
            <fileNamePattern>mylogfile-%d{yyyy-MM-dd}.%i.log</fileNamePattern>
        </rollingPolicy>
        <encoder>
            <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
        </encoder>
    </appender>

      

+3


source to share


2 answers


If the property is file

not present, the currently active log file will be inferred from the value fileNamePattern

. Thus, the property file

is optional. It is also important that in sane mode it should remain empty.

Here is a relevant quote from the fileNamePattern documentation :



Note that the file property in RollingFileAppender (the parent of TimeBasedRollingPolicy) can be either set or omitted. By installing the file that contains FileAppender, you can separate the location of the active log file and the location of the archived log files. Current logs will always target the specified file by file property. It follows that the name of the currently active log file will not change over time. However, if you choose to omit the file, then the active file will be recalculated for each period based on the fileNamePattern value. The examples below should clarify this point ...

+5


source


You can specify the path in theNamePattern file:



<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
    <fileNamePattern>/var/log/myapp/mylogfile-%d{yyyy-MM-dd}.log</fileNamePattern>
</rollingPolicy>

      

+1


source







All Articles