gpt4 book ai didi

java - java中log4j重复记录

转载 作者:行者123 更新时间:2023-12-01 06:48:34 25 4
gpt4 key购买 nike

我在java程序中使用了log4j。我用以下方法初始化它:

BasicConfigurator.configure(); // logger configuration
try {
logger.setLevel(Level.DEBUG);
} catch (Exception e) {
System.out.println("Logfile not found");
}

但是,在程序执行期间,我得到 3 个日志语句,而不是 1 个。例如,

3 lines 
1047 [main] INFO ibis.Preproc.Ratings - Added AS TIMEZONE to tZones[0] = GMT-12:00
1047 [main] INFO ibis.Preproc.Ratings - Added AS TIMEZONE to tZones[0] = GMT-12:00
1047 [main] INFO ibis.Preproc.Ratings - Added AS TIMEZONE to tZones[0] = GMT-12:00

而不是一行

1047 [main] INFO ibis.Preproc.Ratings  - Added AS TIMEZONE to tZones[0] = GMT-12:00

是否需要对 log4j 进行任何额外的配置来避免这种情况?

最佳答案

我也经历过类似的行为,结果发现Log4J被配置了不止一次;使用 BasicConfigurator,还使用我忘记的 log4j.xml 文件。难道类路径上有额外的 Log4J 配置吗?

关于java - java中log4j重复记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/621633/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com