Logback rollover on write-only filesystem

166 Views Asked by At

I have a Java application that has to write it's logfiles to a write-only filesystem. The current logging configuration has a TimeBasedRollingPolicy that rolls over every day. Unfortunately, the rollover fails on the write-only filesystem since a rename is not allowed.

Is it possible to configure Logback, so that it creates the logfiles with the name that already includes the date pattern?

1

There are 1 best solutions below

0
On

Ok, that was easy. All I had to do was remove the file element from the appender. Changing the configuration from this:

<appender name="FILE"
    class="ch.qos.logback.core.rolling.RollingFileAppender">
    <file>logs/server.log</file>
    <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
       <fileNamePattern>logs/%d{yyyy-MM-dd}-server.log</fileNamePattern>
    ...

to this

<appender name="FILE"
    class="ch.qos.logback.core.rolling.RollingFileAppender">
    <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
       <fileNamePattern>logs/%d{yyyy-MM-dd}-server.log</fileNamePattern>
    ...

By leaving out the file-element, the TimeBasedRollingPolicy simply uses the name configured in the fileNamePattern element and doesn't rename on rollover.