2

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.

adarsh
  • 348
  • 1
  • 4
  • 17
  • Did you find any solution to this? I am also looking for the same. – Neerav Vadodaria May 03 '19 at 05:15
  • I have extended the SizeAndTimeBasedRollingPolicy with S3 upload option and it worked like a charm. Please refer to the same link which I have given in the problem statement for reference. – adarsh May 13 '19 at 08:52

1 Answers1

0

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.

adarsh
  • 348
  • 1
  • 4
  • 17