Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Logback: One file with maximum file size

my system support team needs one simple log-file, with a maximum size of 10MB. Older log-lines can be deleted when the file reaches 10MB. So roll out the oldest lines.

What is a good appender for this? I have one appender, but this still created a second file, and then starts again with an empty new file. This is not what my support team wants.

Help is appreciated.

<configuration>
    <appender name="TEST" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <file>${LOG_HOME}/test.log</file>
        <rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
            <fileNamePattern>${LOG_HOME}/test.%i.log</fileNamePattern>
            <minIndex>1</minIndex>
            <maxIndex>1</maxIndex>
        </rollingPolicy>
        <triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
            <maxFileSize>10MB</maxFileSize>
        </triggeringPolicy>
        <encoder>
            <pattern>%date %-5level [%thread] - %mdc{loginName} - [%logger]- %msg%n</pattern>
        </encoder>
    </appender>

  <root level="DEBUG">
    <appender-ref ref="FILE" />
  </root>
</configuration>
like image 865
Dimitri Dewaele Avatar asked Oct 10 '13 09:10

Dimitri Dewaele


1 Answers

Keeping everything in a single file and constantly adding the most recent while deleting the oldest lines is going to perform really really poorly. I suspect that logback can't be made to do this.

What I suggest is you use the regular size based policy, configure it to stay inside your 10MB limit overall, then just concatenate the files when you grab them.

like image 168
kbyrd Avatar answered Oct 13 '22 15:10

kbyrd