为什么 Level.FINE 日志记录消息未显示?
JavaDocs for java.util.logging.Level
state:
按降序排列的级别为:
-
SEVERE
(最大值) WARNING
INFO
CONFIG
FINE
FINER
-
FINEST
(最小值)
源
import java.util.logging.*;
class LoggingLevelsBlunder {
public static void main(String[] args) {
Logger logger = Logger.getAnonymousLogger();
logger.setLevel(Level.FINER);
System.out.println("Logging level is: " + logger.getLevel());
for (int ii=0; ii<3; ii++) {
logger.log(Level.FINE, ii + " " + (ii*ii));
logger.log(Level.INFO, ii + " " + (ii*ii));
}
}
}
输出
Logging level is: FINER
Jun 11, 2011 9:39:23 PM LoggingLevelsBlunder main
INFO: 0 0
Jun 11, 2011 9:39:24 PM LoggingLevelsBlunder main
INFO: 1 1
Jun 11, 2011 9:39:24 PM LoggingLevelsBlunder main
INFO: 2 4
Press any key to continue . . .
问题陈述
我的示例将 设置为 ,因此我期望每个循环看到 2 条消息。相反,我看到每个循环都有一条消息(消息丢失)。Level
FINER
Level.FINE
问题
为了看到(或)输出,需要改变什么?FINE
FINER
FINEST
更新(解决方案)
多亏了Vineet Reynolds的回答,这个版本按照我的期望工作。它显示3条消息和3条消息。INFO
FINE
import java.util.logging.*;
class LoggingLevelsBlunder {
public static void main(String[] args) {
Logger logger = Logger.getAnonymousLogger();
// LOG this level to the log
logger.setLevel(Level.FINER);
ConsoleHandler handler = new ConsoleHandler();
// PUBLISH this level
handler.setLevel(Level.FINER);
logger.addHandler(handler);
System.out.println("Logging level is: " + logger.getLevel());
for (int ii=0; ii<3; ii++) {
logger.log(Level.FINE, ii + " " + (ii*ii));
logger.log(Level.INFO, ii + " " + (ii*ii));
}
}
}