日志记录
一、日志记录器
Logger logger = Logger.getLogger(全限定类名);
二、 日志级别
logger.log(Level.SEVERE,"severe");
logger.log(Level.WARNING,"warning");
logger.log(Level.INFO,"info");
logger.log(Level.CONFIG,"config");
logger.fine("fine");
logger.finer("finer");
logger.finest("finest");
三、自定义日志文件
@Test
public void testLogConfig() throws Exception{
Logger logger = Logger.getLogger("全限定类名");
logger.setUseParentHandlers(false);
ConsoleHandler consoleHandler = new ConsoleHandler();
SimpleFormatter simpleFormatter = new SimpleFormatter();
consoleHandler.setFormatter(simpleFormatter);
logger.addHandler(consoleHandler);
logger.setLevel(Level.ALL);
consoleHandler.setLevel(Level.ALL);
FileHandler fileHandler = new FileHandler("/logs/jul.log");
fileHandler.setFormatter(simpleFormatter);
logger.addHandler(fileHandler);
}