javalogbacklog-rotationlogback-classic

Is there any way to add a delay before compressing the rotated log file


I need to add a delay of some unit time before compressing the rotated log file. I am using logback-core and my xml looks like this:-

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<appender name="file" class="ch.qos.logback.core.rolling.RollingFileAppender">
    <file>app.log</file>
    <rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">

        <fileNamePattern>app-%d{yyyy-MM-dd}.%i.log.gz</fileNamePattern>
        <maxFileSize>1GB</maxFileSize>
        <maxHistory>7</maxHistory>
        <totalSizeCap>7GB</totalSizeCap>
    </rollingPolicy>
    <encoder>
        <pattern>%d{yyyy-MM-dd HH:mm:ss} ​%-5level ​%logger{35}- ​%msg%n</pattern>
    </encoder>
</appender>
<root level="INFO">
    <appender-ref ref="file"/>
</root>
</configuration>

Is there any way to do it? I have seen a way to extend the Rolling policy class here, but not sure if similar way can work here.


Solution

  • I have solved this problem by application Cron.

    First I updated the logback configuration to not to compress and just simply rotate the logs. Then my Cron runs at specific time and gathers all logs which have been rotated and then passes it to next module which does the compression part.