gpt4 book ai didi

java.util.log,使用 3 个不同的记录器实例/日志文件,获取 .1 .2 等

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:35:05 26 4
gpt4 key购买 nike

我想弄清楚为什么要生成多个版本的日志文件(.1、.2 等)。我的项目需要 3 个独立的记录器,我正在使用 java.util.log 并按如下方式设置我的记录器:

logger = Logger.getLogger("Logger");
logger.addHandler(new FileHandler(logFileName));
statsLogger = Logger.getLogger("StatsLogger");
statsLogger.addHandler(new FileHandler(statsLogFileName));
alarmLogger = Logger.getLogger("AlarmLogger");
alarmLogger.addHandler(new FileHandler(alarmLogFileName));

我的日志属性文件:

handlers=java.util.logging.ConsoleHandler java.util.logging.FileHandler
java.util.logging.FileHandler.append=true
java.util.logging.FileHandler.level=INFO
java.util.logging.ConsoleHandler.level=INFO
java.util.logging.ConsoleHandler.formatter=com.package.LogFormatter
java.util.logging.FileHandler.formatter=com.package.LogFormatter

这似乎有效,据我所知……事情似乎被记录到正确的日志文件中。关于可能导致此问题的任何想法?

感谢任何想法

最佳答案

根据 FileHandler javadoc http://docs.oracle.com/javase/1.4.2/docs/api/java/util/logging/FileHandler.html#FileHandler

Normally the "%u" unique field is set to 0. However, if the FileHandler tries to open the filename and finds the file is currently in use by another process it will increment the unique number field and try again. This will be repeated until FileHandler finds a file name that is not currently in use. If there is a conflict and no "%u" field has been specified, it will be added at the end of the filename after a dot. (This will be after any automatically added generation number.)

您是否有多个正在运行的进程使用相同的日志配置?还要检查任何旧的测试进程是否未显示在 Windows 进程查看器或顶部。

关于java.util.log,使用 3 个不同的记录器实例/日志文件,获取 .1 .2 等,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8920573/

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