Partial .gz file written by log4j2

1k views Asked by At

I have the following log configuration.

    <RollingRandomAccessFile name="RollingReqAppender"
        fileName="/usr/test/req.log"
        filePattern="/usr/test/req.log.%d{yyyy-MM-dd-HH}.%i.gz"
        immediateFlush="true" append="true">
        <PatternLayout>
            <Pattern>%d{yyyy-MM-dd HH:mm:ss.SSS Z}%m%n</Pattern>
        </PatternLayout>
        <Policies>
            <SizeBasedTriggeringPolicy size="500 MB"/>
            <TimeBasedTriggeringPolicy interval="1" modulate="true" />
        </Policies>
    </RollingRandomAccessFile>

When the log is rolled over (based on time or size), it is gzipped. Gzipping the file takes some time (seconds to minutes depending on load). The problem is that the file is gzipped in place, and while it is being gzipped, the partially gzipped file is stored in the same folder with the same name as the final gzip file. e.g.: /usr/test/req.log.2017-01-03-02.1.gz

This causes problems for the file's consumer, which attempts to process the partial file. I want to be able to distinguish between a partial gzipped file and a completed gzipped file. For example, I would like to setup a configuration that while the file is being gzipped, it is written with a different name e.g.: /usr/test/req.log.2017-01-03-02.1.temp.gz and once it is completely gzipped the name is changed to the final name /usr/test/req.log.2017-01-03-02.1.gz

How can I achieve this?

2

There are 2 answers

0
Remko Popma On BEST ANSWER

Log4j2 currently does not behave like you describe. So there is no configuration to make this happen.

Please raise a feature request on the Log4j2 JIRA issue tracker. The fastest way to achieve this is to provide a patch with unit test.

0
Sampras On

This feature was added to log4j2 version 2.9.0 https://issues.apache.org/jira/browse/LOG4J2-1766