Log4j2错误处理 [英] Log4j2 Error Handling

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

问题描述

由于我发现了log4j 1.2.x的一些性能问题,因此我尝试迁移到log4j2.

Since I discovered some performance issues with log4j 1.2.x, I tried migrating to log4j2.

现在,我遇到了找不到解决方案的问题. 我必须将用于log4j 1.2.x的配置文件重写为与v2兼容的配置文件. 当我到达称为"errorHandler"的附加程序内部的属性时,就会发生问题.

Now I encountered a problem for which I can't find a solution. I have to rewrite the configuration file that was for log4j 1.2.x into a v2 compatible one. Problem occurs when I reached the property inside of an appender, called "errorHandler".

在这里,errorHandler出现在我的log4j 1.2.x上下文中:

Here is where errorHandler appears in my log4j 1.2.x context:

<appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender">
    <errorHandler class="org.jboss.logging.util.OnlyOnceErrorHandler"/>
    <param name="Target" value="System.out"/>
    <param name="Threshold" value="WARN"/>
    <layout class="org.apache.log4j.PatternLayout">
        <param name="ConversionPattern" value="%d %-5p [%t] %c - %m%n"/>
    </layout>
</appender>

有人能告诉我在errorHandler的log4j2中,如果存在的话,这是一个相似的属性吗? 也许,log4j2中的另一种选择会给我完全相同的结果?

Could anybody tell me, which is the similar property, if exists one, in the log4j2 for errorHandler? Or maybe, another alternative in log4j2 that would give me the exactly same result?

谢谢.

推荐答案

Log4j2提供了 FailoverAppender ,如果主附加程序失败,它将调用辅助附加程序.您可以有一个辅助附加程序列表,log4j会尝试所有这些附加程序,直到成功为止.

Log4j2 provides a FailoverAppender that will invoke the secondary appender if the primary appender fails. You can have a list of secondary appenders and log4j will try all of them until one succeeds.

请注意,在使用FailoverAppender时,应使用ignoreExceptions=false配置主要和次要附加程序.

Note that when using a FailoverAppender you should configure your primary and secondary appenders with ignoreExceptions=false.

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

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