LogImportersLoader { public Collection<LogImporter> loadPropertyPatternFileFromDir(File dir) throws InitializationException { ArrayList<LogImporter> logImporters = new ArrayList<>(); File[] listFiles = dir.listFiles(pathname -> (pathname.isFile() && pathname.getName().endsWith("pattern"))); if (listFiles != null) { StringBuilder exceptionMessages = new StringBuilder(); for (File file : listFiles) { try (FileInputStream is = new FileInputStream(file)) { Properties p = new Properties(); Log4jPatternMultilineLogParser parser = new Log4jPatternMultilineLogParser(); p.load(is); parser.getParserDescription().setFile(file.getAbsolutePath()); if (p.getProperty(Log4jPatternMultilineLogParser.PROPERTY_TYPE, "").equals("log4j")) { LogImporterUsingParser logImporter = new LogImporterUsingParser(parser); logImporter.init(p); logImporters.add(logImporter); } else if (p.getProperty(Log4jPatternMultilineLogParser.PROPERTY_TYPE, "").equals("log4j-native")) { parser.getParserDescription().setFile(file.getAbsolutePath()); Log4jUtil.parsePattern(p); LogImporterUsingParser logImporter = new LogImporterUsingParser(parser); logImporter.init(p); logImporters.add(logImporter); } else if (p.getProperty(Log4jPatternMultilineLogParser.PROPERTY_TYPE, "").equals("json")) { final JsonLogParser jsonLogParser = new JsonLogParser(); jsonLogParser.init(p); logImporters.add(new LogImporterUsingParser(jsonLogParser)); } else { LOGGER.error("Unknown log type: " + p.getProperty(Log4jPatternMultilineLogParser.PROPERTY_TYPE, "")); } } catch (Exception e) { LOGGER.error( "Can't load property file based logger [" + file.getName() + ": " + e.getMessage(), e); if (exceptionMessages.length() > 0) exceptionMessages.append("\n"); exceptionMessages.append("Can't load property file based logger [") .append(file.getName()).append(": ").append(e.getMessage()); } } if (exceptionMessages.length() > 0) throw new InitializationException(exceptionMessages.toString()); } return logImporters; }  Collection<LogImporter> loadInternalLogImporters(); Collection<LogImporter> load(File dir); Collection<LogImporter> loadPropertyPatternFileFromDir(File dir); static final Logger LOGGER; }
@Test public void testLoadPropertyFileBased() throws InitializationException, URISyntaxException { LogImportersLoader importersLoader = new LogImportersLoader(); Collection<LogImporter> loadPropertyFileBased = importersLoader.loadPropertyPatternFileFromDir(getFile(("plugins/logimporters/"))); AssertJUnit.assertEquals(3, loadPropertyFileBased.size()); }