我在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/