private LogFactory() { logTask = new FileLogTask(logTree); LogConfigParser parser = new XmlLogConfigParser(); boolean success = parser.parse((fileLog) -> logTree.put(fileLog.getName(), fileLog)); if (!success) { System.out.println("log configuration parsing failure!"); } if (logTree.get(LogConfigParser.DEFAULT_LOG_NAME) == null) { FileLog fileLog = parser.createDefaultLog(); logTree.put(fileLog.getName(), fileLog); } start(); }
@Override public boolean parse(Action1<FileLog> action) { Dom dom = new DefaultDom(); Document doc = dom.getDocument(DEFAULT_XML_CONFIG_FILE_NAME); if (doc == null) { return false; } Element root = dom.getRoot(doc); List<Element> loggerList = dom.elements(root, "logger"); if (loggerList == null || loggerList.isEmpty()) { return false; } else { for (Element e : loggerList) { String name = dom.getTextValueByTagName(e, "name", DEFAULT_LOG_NAME); String level = dom.getTextValueByTagName(e, "level", DEFAULT_LOG_LEVEL); String path = dom.getTextValueByTagName(e, "path", DEFAULT_LOG_DIRECTORY.getAbsolutePath()); boolean consoleEnabled = ConvertUtils.convert(dom.getTextValueByTagName(e, "enable-console"), DEFAULT_CONSOLE_ENABLED); int maxFileSize = ConvertUtils.convert(dom.getTextValueByTagName(e, "max-file-size"), DEFAULT_MAX_FILE_SIZE); action.call(createLog(name, level, path, consoleEnabled, maxFileSize)); } } return true; }
private LogFactory() { logTask = new FileLogTask(logTree); LogConfigParser parser = new XmlLogConfigParser(); boolean success = parser.parse(new Action1<FileLog>() { @Override public void call(FileLog fileLog) { logTree.put(fileLog.getName(), fileLog); } }); if (!success) { parser = new PropertiesLogConfigParser(); success = parser.parse(new Action1<FileLog>() { @Override public void call(FileLog fileLog) { logTree.put(fileLog.getName(), fileLog); } }); } if (!success) { System.out.println("log configuration parsing failure!"); } if (logTree.get(LogConfigParser.DEFAULT_LOG_NAME) == null) { FileLog fileLog = parser.createDefaultLog(); logTree.put(fileLog.getName(), fileLog); } logTask.start(); }
c.setLogFilter(dom.getTextValueByTagName(e, "log-filter", DEFAULT_LOG_FILTER)); c.setMaxSplitTime(dom.getTextValueByTagName(e, "max-split-time", DEFAULT_MAX_SPLIT_TIME.getValue())); action.call(createLog(c));