private static Logger createLogger(ConfLogger confLog) { Logger logger = new Logger(confLog.getLogName()); logger.setLevel(confLog.getLevel()); Set<ConfHandler> handlerSet = confLog.getHandlers(); for (ConfHandler confHandler : handlerSet) { if (confHandler instanceof ConFileHandler) { ConFileHandler conFileHandler = (ConFileHandler) confHandler; Handler handler = ObjectFactory.getFileHandler(); FileHandler fileHandler = (FileHandler) handler; fileHandler.setName(conFileHandler.getName()); fileHandler.setFileName(conFileHandler.getFileName()); fileHandler.setFormater(conFileHandler.getFormate()); try { fileHandler.init(); } catch (IOException ex) { ex.printStackTrace(); } // to do: check it logger.addHandler(fileHandler); } else if (confHandler instanceof ConfHandler) { Handler handler = ObjectFactory.getConsoleHandler(); handler.setName(confHandler.getName()); logger.addHandler(handler); } } return logger; }
public static Logger getLogger(String pack) { Logger logger = null; if (logMap.containsKey(pack)) { logger = logMap.get(pack); } else { ConfLogger confLog = getLoggerConfig(pack); if (confLog.getLogName().equals("root")) { confLog.setLogName(pack); logger = createLogger(confLog); } else { logger = createLogger(confLog); Logger rootLogger = createLogger(getLoggerConfig("root")); rootLogger.setLogName(pack); logger.setRootLogger(rootLogger); logger.setUseRootLogger(true); } logMap.put(logger.getLogName(), logger); } return logger; }