Save Disk Space with Log Compression in Logback

Minni Arora
Naukri Engineering
Published in
Sep 21, 2022

Would like to briefly share about a simple yet highly useful method of file compression in Logback.

It has helped us resolve the disk space issue on one of our production servers that was not vertically scalable thereby saving efforts of replacing it and the cost of procuring a new one. The file sizes got reduced to 1/10th with it.

Logback has an inbuilt support for automatic compression. When we define a RollingFileAppender with a TimeBasedRollingPolicy, the feature is enabled if the value of the fileNamePattern option ends with .gz or .zip

For example,

<appender name="myAppender"
class="ch.qos.logback.core.rolling.RollingFileAppender"
>
<encoder>
<pattern>%p %c{1.} [%t] %m%n</pattern>
</encoder>
<File>${LOG_FILE}/myaccess.log</File>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>${LOG_FILE}/myaccess.%d.log.gz</fileNamePattern>
<maxHistory>2</maxHistory>
</rollingPolicy>
</appender>

Make use of it and get rid of the Disk Utilization Alerts and Manual Cleanups!!

--

--