log4j logging twice

前端 未结 9 1631
眼角桃花
眼角桃花 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:38

    I had the same problem, and fixed by removing all appenders from the root logger. I don't know why, but solve my problem and I'm sharing:

            // Root
        rootLogger = Logger.getRootLogger();
        rootLogger.removeAllAppenders(); // Solve my problem
            // CSV
        csvLogger = rootLogger.getLogger("csvLogger");
            // Txt
        txtLogger = rootLogger.getLogger("txtLogger");
    

    Without this extra line, even setting additivity to false, whenever I log with my csvLogger or txtLogger it logs twice.

提交回复
热议问题