记录级别
Java Logging Api 有 7 个级别 。降序的级别为:
SEVERE
(最高价值)WARNING
INFO
CONFIG
FINE
FINER
FINEST
(最低价值)
默认级别为 INFO
(但这取决于系统并使用虚拟机)。
注意 :还有 OFF
(可用于关闭注销)和 ALL
(OFF
的对位)。
代码示例:
import java.util.logging.Logger;
public class Levels {
private static final Logger logger = Logger.getLogger(Levels.class.getName());
public static void main(String[] args) {
logger.severe("Message logged by SEVERE");
logger.warning("Message logged by WARNING");
logger.info("Message logged by INFO");
logger.config("Message logged by CONFIG");
logger.fine("Message logged by FINE");
logger.finer("Message logged by FINER");
logger.finest("Message logged by FINEST");
// All of above methods are really just shortcut for
// public void log(Level level, String msg):
logger.log(Level.FINEST, "Message logged by FINEST");
}
}
默认情况下,运行此类将仅输出级别高于 CONFIG
的消息:
Jul 23, 2016 9:16:11 PM LevelsExample main
SEVERE: Message logged by SEVERE
Jul 23, 2016 9:16:11 PM LevelsExample main
WARNING: Message logged by WARNING
Jul 23, 2016 9:16:11 PM LevelsExample main
INFO: Message logged by INFO