Java之Logger日志(Java8特性)
Posted 星瑞的随笔
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Java之Logger日志(Java8特性)相关的知识,希望对你有一定的参考价值。
1 import java.util.logging.Level; 2 import java.util.logging.Logger; 3 4 public class LoggingDemo { 5 public static final Logger logger = Logger.getLogger("LoggingDemo.class"); 6 7 public static void main(String args[]) { 8 Level level = Level.parse("FINEST"); 9 logger.info(level.toString()); 10 11 //下面的消息将被输出 12 logger.setLevel(level); 13 logger.info("this is an info"); 14 logger.warning("this is a warn"); 15 logger.severe("this is a severe"); 16 // logger.config("config"); 17 // logger.fine("fine"); 18 // logger.finer("finer"); 19 // logger.finest("finest"); 20 21 logger.info("LoggerName: " + logger.getName()); 22 logger.info("LoggerLevelName: " + logger.getLevel().getName()); 23 24 } 25 }
运行结果:
五月 23, 2018 5:13:24 下午 org.study2.java8.logging.LoggingDemo main 信息: FINEST 五月 23, 2018 5:13:24 下午 org.study2.java8.logging.LoggingDemo main 信息: this is an info 五月 23, 2018 5:13:24 下午 org.study2.java8.logging.LoggingDemo main 警告: this is a warn 五月 23, 2018 5:13:24 下午 org.study2.java8.logging.LoggingDemo main 严重: this is a severe 五月 23, 2018 5:13:24 下午 org.study2.java8.logging.LoggingDemo main 信息: LoggerName: LoggingDemo.class 五月 23, 2018 5:13:24 下午 org.study2.java8.logging.LoggingDemo main 信息: LoggerLevelName: FINEST
以上是关于Java之Logger日志(Java8特性)的主要内容,如果未能解决你的问题,请参考以下文章