StreamLogger extends Thread { public StreamLogger(InputStream inputStream, Logger logger, Marker marker) { this.inputStream = checkNotNull(inputStream, "inputStream is null"); this.logger = checkNotNull(logger, "logger is null"); this.marker = checkNotNull(marker, "marker is null"); setName(marker.getName()); setDaemon(true); } StreamLogger(InputStream inputStream, Logger logger, Marker marker); @Override void run();  }
@Test public void testStreamLogger() throws InterruptedException { final List<String> lines = Lists.newCopyOnWriteArrayList(); final byte[] bytes = "line1\nline2\nline3".getBytes(Charsets.UTF_8); ByteArrayInputStream inputStream = new ByteArrayInputStream(bytes); final StreamLogger logger = new StreamLogger(inputStream, LOG, MarkerFactory.getMarker("test")) { @Override protected void log(Logger logger, Marker marker, String line) { logger.info(marker, line); lines.add(line); } }; logger.start(); logger.join(); assertThat(lines).contains("line1", "line2", "line3"); }