log4j logging twice

前端 未结 9 1630
眼角桃花
眼角桃花 2021-02-04 23:02

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         


        
9条回答
  •  孤独总比滥情好
    2021-02-04 23:54

    Just simply add

    logger.setadditivity(false);
    

    to your code (Reference).

    We are having double results in the console, it's because appenders are not singletons, they are additive. Meaning, a category inherits all the appenders from its ancestors (by default). If we add an appender to a category and it writes to the same underlying stream (console, same file etc.) as some other appender, the same log message will appear twice (or more) in the log. In addition, if two categories in a hierarchy are configured to use the same appender name, Log4j will write twice to that appender. Configured for that category

提交回复
热议问题