logback / LOGBACK-1776 [Open] SizeAndTimeBasedRollingPolicy does not take into account the initial size of an existing log file
============================== Here's what changed in this issue in the last few minutes. This issue has been created This issue is now assigned to you. View or comment on issue using this link https://jira.qos.ch/browse/LOGBACK-1776 ============================== Issue created ------------------------------ Ceki Gülcü created this issue on 25/Oct/24 15:25 Summary: SizeAndTimeBasedRollingPolicy does not take into account the initial size of an existing log file Issue Type: Bug Assignee: Logback dev list Created: 25/Oct/24 15:25 Environment: Dependency: logback-classic:1.5.9 Java: 17 System: windows 10 Priority: Major Reporter: Ceki Gülcü Description: Problem: when using SizeAndTimeBasedRollingPolicy and setting the maxFileSize field, if logback writes to an already existing log file (a file that was created before running the application), it will not rotate the file if the initial size is already over maxFileSize or if during execution the file exceeds maxFileSize, but it will rotate the log file only after writing maxFileSize bytes to the file, regardless of its actual size Reproducer {code:java} package com.example; import org.slf4j.Logger; import org.slf4j.LoggerFactory; public class App { private static final Logger LOGGER = LoggerFactory.getLogger(App.class); public static void main(String[] args) { for (int i = 0; i < 20000; i++) { LOGGER.info("X".repeat(55)); } } } {code} logback.xml {code:xml} <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE configuration> <configuration> <import class="ch.qos.logback.classic.encoder.PatternLayoutEncoder"/> <import class="ch.qos.logback.core.rolling.RollingFileAppender"/> <import class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy"/> <appender name="ROLLING" class="RollingFileAppender"> <rollingPolicy class="SizeAndTimeBasedRollingPolicy"> <fileNamePattern>mylog-%d{yyyy-MM-dd}.%i.txt</fileNamePattern> <maxFileSize>1MB</maxFileSize> <maxHistory>90</maxHistory> <totalSizeCap>20GB</totalSizeCap> </rollingPolicy> <encoder class="PatternLayoutEncoder"> <pattern>%msg%n</pattern> </encoder> </appender> <root level="DEBUG"> <appender-ref ref="ROLLING"/> </root> </configuration> {code} What happens when running the application the first time: If there are no existing log files following the fileNamePattern: 2 log files will be generated properly {code} mylog-2024-10-11.0.txt 1025 KB mylog-2024-10-11.1.txt 90 KB {code} What happens when running the application multiple times after the first: The existing log files keep getting written for maxFileSize bytes and no rotation occurs {code} mylog-2024-10-11.0.txt 2049 KB mylog-2024-10-11.1.txt 179 KB {code} {code} mylog-2024-10-11.0.txt 3073 KB mylog-2024-10-11.1.txt 268 KB {code} ============================== This message was sent by Atlassian Jira (v9.6.0#960000-sha1:a3ee8af) _______________________________________________ logback-dev mailing list logback-dev@qos.ch https://mailman.qos.ch/cgi-bin/mailman/listinfo/logback-dev