Appender骨架(Log4j2) [英] AppenderSkeleton (Log4j2)

查看:69
本文介绍了Appender骨架(Log4j2)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图将扩展了 org.apache.log4j.AppenderSkeleton 的类从旧版本的log4j迁移到log4j 2.

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,

以此为基础构建的Appender在Log4j 2中被忽略.

Appenders constructed using this are ignored in Log4j 2.

该课程的网站上.

这是否意味着,如果我使用的是Log4j 2,则应该扩展此类?如果是,我应该用什么替代?ConsoleAppender会成功吗?

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?

推荐答案

Log4j 2中的Appender实现了Appender接口.大多数Appender都会扩展

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.

您还将注意到,大多数Appender都使用Manager来执行大部分工作.这是因为始终在重新配置期间重新创建Appender,这可能会导致问题.仅当更改了特定于该Manager的属性时,才会重新创建Manager,否则新的Appender实例将重用以前的Manager.

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.

这篇关于Appender骨架(Log4j2)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆