@Test
public void testDumpingSchedulerLogs() throws Exception {

  Map<Appender, Priority> levels = new HashMap<>();
  String logFilename = "test.log";
  Logger logger = LoggerFactory.getLogger(TestAdHocLogDumper.class);
  if (isLog4jLogger(this.getClass())) {
    for (Enumeration appenders = LogManager.getRootLogger().
        getAllAppenders(); appenders.hasMoreElements();) {
      Object obj = appenders.nextElement();
      if (obj instanceof AppenderSkeleton) {
        AppenderSkeleton appender = (AppenderSkeleton) obj;
        levels.put(appender, appender.getThreshold());
      }
    }
  }
  AdHocLogDumper dumper = new AdHocLogDumper(this.getClass().getName(),
      logFilename);
  dumper.dumpLogs("DEBUG", 1000);
  LOG.debug("test message 1");
  LOG.info("test message 2");
  File logFile = new File(logFilename);
  Assert.assertTrue(logFile.exists());
  Thread.sleep(2000);
  long lastWrite = logFile.lastModified();
  Assert.assertTrue(lastWrite < Time.now());
  Assert.assertTrue(logFile.length() != 0);
  // make sure levels are set back to their original values
  if (isLog4jLogger(this.getClass())) {
    for (Enumeration appenders = LogManager.getRootLogger().
        getAllAppenders(); appenders.hasMoreElements();) {
      Object obj = appenders.nextElement();
      if (obj instanceof AppenderSkeleton) {
        AppenderSkeleton appender = (AppenderSkeleton) obj;
        Assert.assertEquals(levels.get(appender), appender.getThreshold());
      }
    }
  }
  boolean del = logFile.delete();
  if(!del) {
    LOG.info("Couldn't clean up after test");
  }
}