This feature already exists in the log. Take a look at the appenders section, in particular the time-based policies .
Quote:
Like FixedWindowRollingPolicy , TimeBasedRollingPolicy supports automatic file compression. This function is activated if the value of the fileNamePattern parameter ends with .gz or .zip .
Also take a look at calendar policies based on time and size .
You can configure rollovers after one log file reaches a certain limit.
I do not believe that writing directly to a compressed GZIP file for each log statement would be feasible, since it would create quite a lot of overhead. Using a combination of existing features sounds reasonable to me.
source share