logback log file size exceed

40 Views Asked by At

I have logback configuration like this :

<configuration>
    <property name="HOME_LOG" value="/home/mah454/logs/app.log"/>
    <appender name="FILE-ROLLING" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <file>${HOME_LOG}</file>

        <rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
            <fileNamePattern>/home/mah454/logs/app.%d{yyyy-MM-dd}.%i.log.gz</fileNamePattern>
            <maxFileSize>1MB</maxFileSize>
            <totalSizeCap>5MB</totalSizeCap>
            <maxHistory>3</maxHistory>
        </rollingPolicy>

        <encoder>
            <pattern>%d %p [%t] %m%n</pattern>
        </encoder>
    </appender>

    <logger name="com.sample" level="debug" additivity="false">
        <appender-ref ref="FILE-ROLLING"/>
    </logger>

    <root level="error">
        <appender-ref ref="FILE-ROLLING"/>
    </root>
</configuration>

and simple infinit loop for test logback limitations :

package com.sample;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class MainClass {
    private static final Logger logger = LoggerFactory.getLogger(MainClass.class);

    public static void main(String[] args) {
        while (true) {
            logger.info("This is INFO");
        }
    }
}

Why size of file exceed 1MB i configured on logback.xml ?
and why never archived ?

1

There are 1 best solutions below

0
mah454 On

Fixed .
The size of file depend to logback.xml fileNamePattern tag !
I changed to :

app.%d{yyyy-MM-dd HH:mm:ss}.%i.log.gz