Log4j Migration - How to migrate Custom File Appender with log4j bridge or logj2

Viewed 285

I have one customer appender class that was implemented in log4j 1 as below:

import org.apache.log4j.FileAppender;
import org.apache.log4j.helpers.CountingQuietWriter;
import org.apache.log4j.helpers.LogLog;
...

public class CustomFileAppender extends FileAppender
{
    ...
    @Override
    protected void setQWForFiles(final Writer writer)
    {
        super.qw = new CountingQuietWriter(writer, super.errorHandler);
    }
}

I'm trying to migrate this class to use bridge (log4j-1.2-api-2.17.1) (and log4j 2 core and api version 2.17.1)

I noticed that:

1> The Log4j bridge does not have FileApennder class. The migration doc did list the FileAppender as one of the supported components

2> log4j 2 File appender cannot be extend as the class is defined as "public final class FileAppender"

My questions are:

1> What is the best way to migrate custom File Appender in this case?

2> What is the equivalent of below classes in log4j2?

  • org.apache.log4j.FileAppender;
  • org.apache.log4j.helpers.CountingQuietWriter
  • org.apache.log4j.helpers.LogLog
1 Answers

log4j2 and the bridge do not contain the classes that log4j1 custom appenders used to extend, therefore you must consider rewriting your custom appender as a new log4j2 plugin. You can get some information from here and here. This post also can give you some inspiration.

Related