Java – logback roll only for file size

I'm using logback 1.0 13. I want my log files to scroll completely based on file size If it takes two hours or two years, I don't care I can't figure out how to do this My appender configuration is as follows:

<appender name="serverFaultFile"
    class="ch.qos.logback.core.rolling.RollingFileAppender">
    <file>/folder/to/log/file.log</file>
    <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
        <fileNamePattern>/folder/to/log/file-%d{yyyy-MM}.%i.log</fileNamePattern>
        <MaxHistory>2</MaxHistory>
        <cleanHistoryOnStart>true</cleanHistoryOnStart>
        <timeBasedFileNamingAndTriggeringPolicy
            class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
            <maxFileSize>10MB</maxFileSize>
            <MaxHistory>9</MaxHistory>
        </timeBasedFileNamingAndTriggeringPolicy>
    </rollingPolicy>
    <encoder>
        <pattern>[%p] [%d{ISO8601}] [%c] [%m]%n</pattern>
    </encoder>
</appender>

This solution rolls every month, which is not what I need I tried to completely delete the –% d {dateformat} modifier, but then I didn't even create / record the file I tried the modifiers% G and% yyyy, but the monthly is so fine because logback obviously allows me to get it (see this bug report) What did I miss?

Solution

You want a sizebasedtriggingpolicy: http://logback.qos.ch/manual/appenders.html#SizeBasedTriggeringPolicy , may be used in combination with fixedwindowrollingpolicy

It used to be a comment, not sure it should get its own answer, but here

The above is the whole content of Java - logback roll only for file size collected and sorted by programming house for you. I hope this article can help you solve the program development problems encountered by Java - logback roll only for file size.

If you think the content of the programming home website is good, you are welcome to recommend the programming home website to programmers and friends.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>