有时候会需要某些功能中使用独立的日志文件,以下为代码示例。
public final static String LOGGER_NAME = "MyFunction"; private static Logger logger = Logger.getLogger(LOGGER_NAME); static { try { File logFile = new File(MainService.getWorkDir(), "MyFunction.log"); FileAppender fileAp = new FileAppender( new PatternLayout("%d %5p (%c:%L) - %m%n"), logFile.getAbsolutePath(), true); logger.setLevel(Level.DEBUG); logger.addAppender(fileAp); } catch (Exception e) { logger.error("", e); } };