Java记录级别
示例
JavaLoggingApi具有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"); //以上所有方法实际上只是 //公共无效日志(级别,字符串味精): 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