Alireza Fattahi
Alireza Fattahi

Reputation: 45553

Perfomance considerations using log4j2 zip

We can ask log4j to gz the log files when using this:

<RollingRandomAccessFile name="TotallogFileAppender"
    fileName="d:/logs/my.log" filePattern="d:/logs/my-%d{yyyy-MM-dd}-%i.log.gz">
    <PatternLayout pattern="${filelayoutPattern}" />
    <Policies>
        <TimeBasedTriggeringPolicy />
        <SizeBasedTriggeringPolicy size="150 MB" />
    </Policies>
    <DefaultRolloverStrategy max="2000" />
</RollingRandomAccessFile>

As the zipping consumes cpu, I wonder when the gzip is done?! Is the log file created and gziped AFTER size or time policy triggered (one time gzip), or it will be gziped while it is writing on the hard disk (continuously gzip). First one seems to have better performance ( Am I correct ?! )

Generally what considerations should be done about the performance of log4j2 archiving the gzip files.

Upvotes: 1

Views: 581

Answers (1)

Remko Popma
Remko Popma

Reputation: 36834

Renaming the file is done in the calling thread, but zipping the old file is done in a separate background thread. The assumption is that a rollover is not a frequent occurrence, so a new background thread is created for each rollover, but your application's performance will generally not be impacted by rollovers.

Upvotes: 1

Related Questions