Log4jSerilizedLogImporter extends AbstractPluginableElement implements LogImporter { @Override public void importLogs(InputStream in, LogDataCollector dataCollector, ParsingContext parsingContext) { try (ObjectInputStream oin = new ObjectInputStream(new BufferedInputStream(in))) { LoggingEvent le; while ((le = (LoggingEvent) oin.readObject()) != null) { LogData translateLog4j = Log4jUtil.translateLog4j(le); translateLog4j.setLogSource(parsingContext.getLogSource()); dataCollector.add(translateLog4j); } } catch (IOException e) { LOGGER.warn(String.format("IOException when reading log4j serialized event: %s", e.getMessage())); } catch (ClassNotFoundException e) { LOGGER.warn(String.format("ClassNotFoundException when reading log4j serialized event %s", e.getMessage())); } finally { IOUtils.closeQuietly(in); } } Log4jSerilizedLogImporter(); @Override int getApiVersion(); @Override void init(Properties properties); @Override void initParsingContext(ParsingContext parsingContext); @Override void importLogs(InputStream in, LogDataCollector dataCollector, ParsingContext parsingContext); @Override TableColumns[] getTableColumnsToUse(); @Override String getKeyStrokeAccelelator(); @Override int getMnemonic(); @Override Icon getIcon();  }
@Test public void testImportLogs() throws IOException, InitializationException { LoggingEvent[] sourceEvents = new LoggingEvent[5]; for (int i = 0; i < sourceEvents.length; i++) { Level info = Level.INFO; String message = Integer.toString(i); long timestamp = i; Logger logger = Logger.getLogger("MyLogger"); LoggingEvent event = new LoggingEvent(null, logger, timestamp, info, message, null); sourceEvents[i] = event; } ByteArrayOutputStream bout = new ByteArrayOutputStream(); ObjectOutputStream oout = new ObjectOutputStream(bout); for (LoggingEvent loggingEvent : sourceEvents) { oout.writeObject(loggingEvent); } oout.flush(); Log4jSerilizedLogImporter importer = new Log4jSerilizedLogImporter(); importer.init(new Properties()); ParsingContext parsingContext = new ParsingContext(); importer.initParsingContext(parsingContext); ProxyLogDataCollector collector = new ProxyLogDataCollector(); importer.importLogs(new ByteArrayInputStream(bout.toByteArray()), collector, parsingContext); LogData[] parsedLogData = collector.getLogData(); assertEquals(sourceEvents.length, parsedLogData.length); for (int i = 0; i < parsedLogData.length; i++) { assertEquals(sourceEvents[i].getTimeStamp(), parsedLogData[i].getDate().getTime()); assertEquals(sourceEvents[i].getMessage(), parsedLogData[i].getMessage()); } }