import java.util.logging.Level;
import java.util.logging.Logger; public class LoggingDemo {
public static final Logger logger = Logger.getLogger("LoggingDemo.class"); public static void main(String args[]) {
Level level = Level.parse("FINEST");
logger.info(level.toString()); //下面的消息将被输出
logger.setLevel(level);
logger.info("this is an info");
logger.warning("this is a warn");
logger.severe("this is a severe");
// logger.config("config");
// logger.fine("fine");
// logger.finer("finer");
// logger.finest("finest"); logger.info("LoggerName: " + logger.getName());
logger.info("LoggerLevelName: " + logger.getLevel().getName()); }
}
运行结果:
五月 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