Cristiano
Cristiano

Reputation: 876

log4j2 new compression algorithm

I would like to use log4j2 RollingFileAppender with a customized compression algorithm (ZStd).

It seems that the compression algorithms supported so far are the ones in the FileExtension enum (zip, gz, bz2, ...), see https://github.com/apache/logging-log4j2/blob/efa64bfad3f67c5b5fed6b25d65ef5ca2212011b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/rolling/FileExtension.java, and I believe it is not possible to add a new one (apart from patching the library).

A solution could be to reimplement the RollingFileAppender using the approach suggested here: https://logging.apache.org/log4j/2.x/manual/extending.html#Appenders, but this would involve a lot of ugly copy and paste, this appender really does a lot of things.

The approach I would like to follow is to create instead a new Action, implementing the AbstractAction interface, but I do not know how to tell log4j2 to execute this action on rollover. Is this doable? Is this the correct way to achieve this goal?

Upvotes: 1

Views: 1078

Answers (1)

rgoers
rgoers

Reputation: 9151

Yes. The Rollover strategy uses FileExtension to automatically add a CompressAction based on the file extension, but you can do this yourself just by configuring a custom Action. While you can look at ZipoCompressAction as a template for how to implement the action, you would also need to look at DeleteAction to see how to declare your custom action as a plugin.

Upvotes: 1

Related Questions