janneob
janneob

Reputation: 959

How to extend log4j2 RollingFileAppender?

I need to copy the gz file after the gzip was done. What is the best way to do this?

  1. There is a way to extend the RollingFileAppender?
  2. Create another appender - but this means that every log line he will perform this task.
  3. Some other way that I don't know of.

Upvotes: 3

Views: 3405

Answers (2)

sriram r
sriram r

Reputation: 39

You cannot extend in in log4j2, because apache have made it a final class in log4j2. In earlier version of log4j you could have easily extended and called the custom class by configuring the appender in the properties file(xml). Their migration steps also doesn't specify how to move this functionality to log4j2.

Upvotes: 3

Remko Popma
Remko Popma

Reputation: 36844

You could specify the target folder of the gz file in the filePattern attribute of the RollingFile configuration. Maybe I'm oversimplifying but I should mention the simple option first.

An alternative is to create a custom plugin action that runs after the rollover. For inspiration look at the source for DeleteAction.

You can configure your plugin similar to how the built-in delete action is configured.

Upvotes: 3

Related Questions