@Override public FileLog createDefaultLog() { Configuration c = new Configuration(); c.setName(DEFAULT_LOG_NAME); c.setLevel(DEFAULT_LOG_LEVEL); c.setPath(DEFAULT_LOG_DIRECTORY.getAbsolutePath()); c.setConsole(false); c.setMaxFileSize(DEFAULT_MAX_FILE_SIZE); c.setCharset(DEFAULT_CHARSET.name()); c.setFormatter(DEFAULT_LOG_FORMATTER); c.setMaxSplitTime(DEFAULT_MAX_SPLIT_TIME.getValue()); return createLog(c); }
private void init() { if (formatter == null) { try { Class<?> clazz = AbstractLogConfigParser.class.getClassLoader().loadClass(c.getFormatter()); formatter = (LogFormatter) clazz.newInstance(); } catch (ClassNotFoundException | IllegalAccessException | InstantiationException e) { e.printStackTrace(); formatter = new DefaultLogFormatter(); } } } });
private void init() { if (filter == null) { try { Class<?> clazz = AbstractLogConfigParser.class.getClassLoader().loadClass(c.getLogFilter()); filter = (LogFilter) clazz.newInstance(); } catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) { e.printStackTrace(); filter = new DefaultLogFilter(); } } } });
} else { for (Element e : loggerList) { Configuration c = new Configuration(); c.setName(dom.getTextValueByTagName(e, "name", DEFAULT_LOG_NAME)); c.setLevel(dom.getTextValueByTagName(e, "level", DEFAULT_LOG_LEVEL)); c.setPath(dom.getTextValueByTagName(e, "path", DEFAULT_LOG_DIRECTORY.getAbsolutePath())); c.setConsole(ConvertUtils.convert(dom.getTextValueByTagName(e, "enable-console"), DEFAULT_CONSOLE_ENABLED)); c.setMaxFileSize(ConvertUtils.convert(dom.getTextValueByTagName(e, "max-file-size"), DEFAULT_MAX_FILE_SIZE)); if (c.getMaxFileSize() < 1024 * 1024 * 10) { System.err.println("the max log file less than 10MB, please set a larger file size"); c.setCharset(dom.getTextValueByTagName(e, "charset", DEFAULT_CHARSET.name())); c.setFormatter(dom.getTextValueByTagName(e, "formatter", DEFAULT_LOG_FORMATTER)); c.setLogNameFormatter(dom.getTextValueByTagName(e, "log-name-formatter", DEFAULT_LOG_NAME_FORMATTER)); 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));
protected FileLog createLog(Configuration c) { FileLog fileLog = new FileLog(); fileLog.setMaxLogFlushInterval(Math.max(c.getMaxLogFlushInterval(), 500L)); fileLog.setName(c.getName()); fileLog.setLevel(LogLevel.fromName(c.getLevel())); fileLog.setMaxFileSize(c.getMaxFileSize()); fileLog.setCharset(Charset.forName(c.getCharset())); if (StringUtils.hasText(c.getPath())) { File file = new File(c.getPath()); success = createLogDirectory(file); if (success) { fileLog.setPath(c.getPath()); fileLog.setFileOutput(true); } else { fileLog.setConsoleOutput(c.isConsole()); } else { fileLog.setConsoleOutput(true); if (StringUtils.hasText(c.getFormatter())) { fileLog.setLogFormatter(new LogFormatter() { if (StringUtils.hasText(c.getLogNameFormatter())) { fileLog.setLogNameFormatter(new LogNameFormatter() { if (StringUtils.hasText(c.getLogFilter())) { fileLog.setLogFilter(new LogFilter() { if (StringUtils.hasText(c.getMaxSplitTime())) {
private void init() { if (formatter == null) { try { Class<?> clazz = AbstractLogConfigParser.class.getClassLoader().loadClass(c.getLogNameFormatter()); formatter = (LogNameFormatter) clazz.newInstance(); } catch (ClassNotFoundException | IllegalAccessException | InstantiationException e) { e.printStackTrace(); formatter = new DefaultLogNameFormatter(); } } } });