Logback: One file with maximum file size
Asked Answered
S

1

6

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>
Sporangium answered 10/10, 2013 at 9:38 Comment(0)
C
6

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.

Callant answered 11/3, 2014 at 18:56 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.