1, Creating a logger
private static final Logger logger = Logger.getLogger(MyClass.class.getName());
2, Create handler
//Handler to receive the log as a file
FileHandler fileHandler = new FileHandler(String filepath, true);
fileHandler.setFormatter(new SimpleFormatter());
//Standard output handler
ConsoleHandler consoleHandler = new ConsoleHandler();
consoleHandler.setLevel(Level.ALL);
3, set a handler for the logger
logger.addHandler(fileHandler);
logger.addHandler(consoleHandler);
logger.setLevel(Level.ALL);
4, set the log level
logger.setLevel(Level.ALL);
5, output log
logger.finest("FNST");
logger.finer("FNR");
logger.fine("FN");
logger.config("CFG");
logger.info("INF");
logger.warning("WNG");
logger.severe("SVR");
Recommended Posts