📜  记录到文件 log4j - Java 代码示例

📅  最后修改于: 2022-03-11 14:52:04.782000             🧑  作者: Mango

代码示例1
// How to log to a file using log4j : 

 String filePath = "D:/Logs/MyFirstLog.log";
 PatternLayout layout = new PatternLayout("%-5p %d %m%n");
 RollingFileAppender appender = new RollingFileAppender(layout, filePath);
 appender.setName("MyFirstLog");
 appender.setMaxFileSize("20MB");
 appender.activateOptions();
 logger.addAppender(appender);
 logger.info("this will be printed in the provided log file");