log4j记录两次 [英] log4j logging twice

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

问题描述

我正在使用log4j记录错误和其他系统信息.但出现两次在INFO级别记录的信息.

I am using log4j to log error and other system information. but come of the info logged twice at INFO level.

public static void main(final String... args) throws Exception {

    LOGGER.info("program started");
    try {
        // try body codes
    } catch (Exception ex) {
        LOGGER.info("program start-up failed.",ex);
    }
}

无论程序何时启动或失败,两次记录的信息,任何人都可以帮助我找出原因.

however when the program starts or failed the information logged twice, any one can help me to find what could be the reason of that.

推荐答案

好像您的消息一次被root记录器记录,又被特定的记录器记录,因为您可能已经配置了两个附加程序(可能位于不同的位置-在属性文件中,然后在代码中.)

Looks like your messages are being logged once by the root logger and again by the specific logger as you may have both the appenders configured (may be at different places -in a properties file and then in code).

这可以通过在记录器上将可加性设置为false来解决. Log4j 手册在添加者和布局"部分中提到了可加性.检查一下

This can be solved by setting additivity to false on your logger. Log4j manual mentions additivity in the Appenders and Layout section.Check that out

这篇关于log4j记录两次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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