[logback-user] size based rollback unexpected behaviour

Hakan Küçük hakanskucuk at gmail.com
Thu Jul 20 12:41:01 CEST 2023


I have a basic spring boot application with the logback.xml below

<configuration>

  <appender name="ROLLING"
class="ch.qos.logback.core.rolling.RollingFileAppender">
    <file>mylog.txt</file>
    <rollingPolicy
class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
      <fileNamePattern>mylog-%d{yyyy-MM-dd}.%i.txt</fileNamePattern>
      <maxFileSize>1MB</maxFileSize>
      <maxHistory>60</maxHistory>
      <totalSizeCap>1GB</totalSizeCap>
    </rollingPolicy>

    <encoder>
      <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} %-4relative [%thread]
%-5level %logger{35} - %msg%n</pattern>
    </encoder>
  </appender>

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


I created logs with the following code to test the rolling.

@Slf4j
@SpringBootApplication
public class LogbackApplication implements CommandLineRunner {

    public static void main(String[] args) {
        SpringApplication.run(LogbackApplication.class, args);
    }

    @Override
    public void run(String... args) throws Exception {
        for (int i = 0; i < 100000; i++) {
            log.debug("This is DEBUG");
            log.info("This is INFO");
            log.warn("This is WARN");
        }
    }
}


I observed a log file of more than 25 MB. It is not rolling. If I put some
sleep statements inside logging, it rolls.

Is it a bug? or am I misconfiguring it? or expected behavior because of
performance reasons?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.qos.ch/pipermail/logback-user/attachments/20230720/75b152ce/attachment-0001.htm>


More information about the logback-user mailing list