Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

S3TimeBasedRollingPolicy does not work as expected. #17

Open
vish91 opened this issue Feb 23, 2019 · 1 comment
Open

S3TimeBasedRollingPolicy does not work as expected. #17

vish91 opened this issue Feb 23, 2019 · 1 comment

Comments

@vish91
Copy link

vish91 commented Feb 23, 2019

It looks like the S3TimeBasedRollingPolicy does not work as expected. When App shuts down, it leaves the last log file as a .tmp file and does not compress it as expected.
Example appender configuration

 <appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
                <file>logs/myapp.csv</file>
                <encoder>
                    <pattern>%d{"yyyy-MM-dd HH:mm:ss.SSSSSSSSS"},%msg%n</pattern>
                </encoder>
                <rollingPolicy class="ch.qos.logback.core.rolling.S3TimeBasedRollingPolicy">
                    <!-- Rollover every hour-->
                    <fileNamePattern>logs/accountID=${accountID}/audit.%d{yyyy-MM-dd_HH}.%i.csv.gz</fileNamePattern>
                    <totalSizeCap>4000KB</totalSizeCap>
                    <s3BucketName>dev</s3BucketName>
                    <s3FolderName>test-buck</s3FolderName>
                    <rolloverOnExit>true</rolloverOnExit>
                    <shutdownHookType>JVM_SHUTDOWN_HOOK</shutdownHookType>
                    <prefixTimestamp>false</prefixTimestamp>
                    <prefixIdentifier>true</prefixIdentifier>
                    <timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
                        <maxFileSize>10KB</maxFileSize>
                    </timeBasedFileNamingAndTriggeringPolicy>
                </rollingPolicy>
            </appender>

screen shot 2019-02-22 at 8 47 59 pm

It should have rolled up the file Index and created a gz , but it didn't seem to have incremented the fileNameCounter or compressed it. Can someone confirm that this seems like a valid issue ? Have been looking in the code but actual process debugging is hard to capture to know what happens when onShutDown() calls the rollover() function.

@nilayspshah
Copy link

nilayspshah commented Mar 23, 2022

The File pattern you are using is: audit.%d{yyyy-MM-dd_HH}.%i.csv.gz

Your temp file is of the format

String tmpTarget = nameOfCompressedFile + System.nanoTime() + ".tmp";

The temp file created in your case, audit.2019-02-22_20.2.csv130..388.tmp will be stored as audit.2019-02-22.2.csv.gz as per convention
Since you already have a compressed file audit.2019-02-22.2.csv.gz, the tmp file could not be compressed

Was the audit.2019-02-22.2.csv.gz present from a previous run?
If not then it we need to check the ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP class as that is responsible for maintaining the currentPeriodsCounter, which is the %i we have in the file name pattern audit.%d{yyyy-MM-dd_HH}.%i.csv.gz

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants