Issue
I am trying to migrate a class that extends org.apache.log4j.AppenderSkeleton
from an old version of log4j to log4j 2. I was reading the JavaDoc for the class, and I read that,
Appenders constructed using this are ignored in Log4j 2.
on the website for the class.
Does this mean, if I am using Log4j 2, I should extend this class? If yes, what should I use as an alternative? Would ConsoleAppender do the trick?
Solution
Appenders in Log4j 2 implement the Appender interface. Most Appenders will extend either AbstractAppender, AbstractOutputStreamAppender, or AbstractWriterAppender. Log4j 2 uses Plugins, which means your appender will have to be annotated with @Plugin and defined as an Appender. Appenders also require a Builder annotated with @PluginBuilderFactory to create the Appender instance from its configuration. You can look at any of Log4j's Appenders, such as FileAppender, for an example.
You will also notice that most of the Appenders use a Manager to perform most of the work. This is because Appenders are always recreated during a reconfiguration, which could lead to problems. The Managers are only recreated if attributes specific to that Manager are changed, otherwise the new Appender instance will reuse the previous Manager.
Answered By - rgoers
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.