@Test
  public void testSlidingLogFiles() throws Exception {
    assertEquals("bad props file", PROPERTIES_FILE,
        System.getProperty("log4j.configurationFile"));

    // Where the log files wll be written
    Path logTemplate = FileSystems.getDefault().getPath(FILE_PATTERN);
    String fileName = logTemplate.getFileName().toString();
    Path parent = logTemplate.getParent();
    try {
      Files.createDirectory(parent);
    } catch (FileAlreadyExistsException e) {
      // OK, fall through.
    }

    // Delete any stale log files left around from previous failed tests
    deleteLogFiles(parent, fileName);

    Logger logger = LogManager.getLogger(LineageLogger.class);

    // Does the logger config look correct?
    org.apache.logging.log4j.core.Logger coreLogger =
        (org.apache.logging.log4j.core.Logger) logger;
    LoggerConfig loggerConfig = coreLogger.get();
    Map<String, Appender> appenders = loggerConfig.getAppenders();

    assertNotNull("sliding appender is missing", appenders.get("sliding"));

    // Do some logging and force log rollover
    int NUM_LOGS = 7;
    logger.debug("Debug Message Logged !!!");
    logger.info("Info Message Logged !!!");

    String errorString = "Error Message Logged ";
    for (int i = 0; i < NUM_LOGS; i++) {
      TimeUnit.MILLISECONDS.sleep(100);
      // log an exception - this produces enough text to force a new logfile
      // (as appender.sliding.policies.size.size=1KB)
      logger.error(errorString + i,
          new RuntimeException("part of a test"));
    }

    // Check log files look OK
    DirectoryStream<Path> stream =
        Files.newDirectoryStream(parent, fileName + ".*");
    int count = 0;
    for (Path path : stream) {
      count++;
      String contents = new String(Files.readAllBytes(path), "UTF-8");
      // There should be one exception message per file
      assertTrue("File " + path + " did not have expected content",
          contents.contains(errorString));
      String suffix = StringUtils.substringAfterLast(path.toString(), ".");
      // suffix should be a timestamp
      try {
        long timestamp = Long.parseLong(suffix);
      } catch (NumberFormatException e) {
        fail("Suffix " + suffix + " is not a long");
      }
    }
    assertEquals("bad count of log files", NUM_LOGS, count);

    // Check there is no log file without the suffix
    assertFalse("file should not exist:" + logTemplate,
        Files.exists(logTemplate));

    // Clean up
    deleteLogFiles(parent, fileName);
  }
Test configuration and use of SlidingFilenameRolloverStrategy
@see SlidingFilenameRolloverStrategy
ql/src/test/org/apache/hadoop/hive/ql/log/TestSlidingFilenameRolloverStrategy.java