@Override public void close() throws IOException { if (rfAppender != null) { rfAppender.stop(); } }
@Override public void stop() throws Exception { fileAppender.stop(); }
@Override public void close() { try { fileAppender.stop(); } catch (Exception e) { // catch any exception to assure logging always works reportError(null, e, CLOSE_FAILURE); } }
@Override public void destroy() { patternLayoutEncoder.stop(); fixedWindowRollingPolicy.stop(); sizeBasedTriggeringPolicy.stop(); rollingFileAppender.stop(); } }
@After public void tearDown() throws Exception { rfa.stop(); }
(RollingFileAppender<ILoggingEvent>) appender; String file = new File(basedir, "logs/wisdom.log").getAbsolutePath(); fileAppender.stop();
private long logOverMultiplePeriods(ConfigParameters cp) { buildRollingFileAppender(cp); final int ticksPerPeriod = 216; int runLength = cp.simulatedNumberOfPeriods * ticksPerPeriod; int startInactivityIndex = cp.startInactivity * ticksPerPeriod; int endInactivityIndex = startInactivityIndex + cp.numInactivityPeriods * ticksPerPeriod; long tickDuration = cp.periodDurationInMillis / ticksPerPeriod; for (int i = 0; i <= runLength; i++) { if (i < startInactivityIndex || i > endInactivityIndex) { Date currentDate = new Date(tbrp.timeBasedFileNamingAndTriggeringPolicy.getCurrentTime()); StringBuilder sb = new StringBuilder("Hello"); String currentDateStr = currentDate.toString(); String iAsString = Integer.toString(i); sb.append(currentDateStr); SpacePadder.spacePad(sb, 66 + (3 - iAsString.length() - currentDateStr.length())); sb.append(iAsString); rfa.doAppend(sb.toString()); } tbrp.timeBasedFileNamingAndTriggeringPolicy.setCurrentTime(tbrp.timeBasedFileNamingAndTriggeringPolicy.getCurrentTime() + tickDuration); add(tbrp.compressionFuture); add(tbrp.cleanUpFuture); waitForJobsToComplete(); } rfa.stop(); return tbrp.timeBasedFileNamingAndTriggeringPolicy.getCurrentTime(); } }
@Test public void stopTimeBasedRollingPolicy() { rfa.setContext(context); tbrp.setFileNamePattern(CoreTestConstants.OUTPUT_DIR_PREFIX + "toto-%d.log.zip"); tbrp.start(); rfa.setRollingPolicy(tbrp); rfa.start(); StatusPrinter.print(context); assertTrue(tbrp.isStarted()); assertTrue(rfa.isStarted()); rfa.stop(); assertFalse(rfa.isStarted()); assertFalse(tbrp.isStarted()); }
private void secondPhase(String testId, String file, String stem, String compressionSuffix, int runLength, String prefix) { rfa1.stop(); if (stem != null) { File f = new File(file); f.setLastModified(currentTime); } StatusManager sm = context.getStatusManager(); sm.add(new InfoStatus("Time when rfa1 is stopped: " + new Date(currentTime), this)); sm.add(new InfoStatus("currentTime%1000=" + (currentTime % 1000), this)); initRollingFileAppender(rfa2, file); initPolicies(rfa2, tbrp2, randomOutputDir + testId + "-%d{" + DATE_PATTERN_WITH_SECONDS + ", GMT}-%i.txt" + compressionSuffix, sizeThreshold, currentTime); for (int i = runLength; i < runLength * 2; i++) { incCurrentTime(100); tbrp2.timeBasedFileNamingAndTriggeringPolicy.setCurrentTime(currentTime); String msg = prefix + i; rfa2.doAppend(msg); addExpectedFileNamedIfItsTime(randomOutputDir, testId, msg, compressionSuffix); } }
private void doRestart(String testId, String patternPart, boolean fileOptionIsSet, int waitDuration) { // change the timestamp of the currently actively file File activeFile = new File(rfa1.getFile()); activeFile.setLastModified(currentTime); incCurrentTime(waitDuration); String filePatternStr = randomOutputDir + patternPart + "-%d{" + DATE_PATTERN_WITH_SECONDS + ", GMT}"; String fileName = fileOptionIsSet ? testId2FileName(testId) : null; initRFA(rfa2, fileName); initTRBP(rfa2, tbrp2, filePatternStr, currentTime); for (int i = 0; i < 3; i++) { rfa2.doAppend("World---" + i); addExpectedFileNamedIfItsTime_ByDate(filePatternStr); incCurrentTime(400); tbrp2.timeBasedFileNamingAndTriggeringPolicy.setCurrentTime(currentTime); add(tbrp2.compressionFuture); add(tbrp2.cleanUpFuture); } rfa2.stop(); }
@Test public void stopFixedWindowRollingPolicy() { rfa.setContext(context); rfa.setFile(CoreTestConstants.OUTPUT_DIR_PREFIX + "toto-.log"); FixedWindowRollingPolicy fwRollingPolicy = new FixedWindowRollingPolicy(); fwRollingPolicy.setContext(context); fwRollingPolicy.setFileNamePattern(CoreTestConstants.OUTPUT_DIR_PREFIX + "toto-%i.log.zip"); fwRollingPolicy.setParent(rfa); fwRollingPolicy.start(); SizeBasedTriggeringPolicy<Object> sbTriggeringPolicy = new SizeBasedTriggeringPolicy<Object>(); sbTriggeringPolicy.setContext(context); sbTriggeringPolicy.start(); rfa.setRollingPolicy(fwRollingPolicy); rfa.setTriggeringPolicy(sbTriggeringPolicy); rfa.start(); StatusPrinter.print(context); assertTrue(fwRollingPolicy.isStarted()); assertTrue(sbTriggeringPolicy.isStarted()); assertTrue(rfa.isStarted()); rfa.stop(); assertFalse(rfa.isStarted()); assertFalse(fwRollingPolicy.isStarted()); assertFalse(sbTriggeringPolicy.isStarted()); }
void generic(String testName, String fileName, String filenamePattern, List<String> expectedFilenameList) throws InterruptedException, IOException { rfa.setName("ROLLING"); initRFA(randomOutputDir + fileName); sizeBasedTriggeringPolicy.setMaxFileSize(new FileSize(100)); fwrp.setMinIndex(0); fwrp.setFileNamePattern(randomOutputDir + filenamePattern); rfa.triggeringPolicy = sizeBasedTriggeringPolicy; rfa.rollingPolicy = fwrp; fwrp.start(); sizeBasedTriggeringPolicy.start(); rfa.start(); int runLength = 40; String prefix = "hello"; for (int i = 0; i < runLength; i++){ Thread.sleep(10); rfa.doAppend(prefix + i); } rfa.stop(); existenceCheck(expectedFilenameList); reverseSortedContentCheck(randomOutputDir, runLength, prefix); }
rollingPolicy.start(); appender.stop(); appender.start();
private void genericTest(String testId, String patternPrefix, String compressionSuffix, boolean fileOptionIsSet, int waitDuration) throws IOException { String fileName = fileOptionIsSet ? testId2FileName(testId) : null; initRFA(rfa1, fileName); String fileNamePatternStr = randomOutputDir + patternPrefix + "-%d{" + DATE_PATTERN_WITH_SECONDS + ", GMT}" + compressionSuffix; initTRBP(rfa1, tbrp1, fileNamePatternStr, currentTime); // compute the current filename addExpectedFileName_ByDate(fileNamePatternStr, getMillisOfCurrentPeriodsStart()); incCurrentTime(1100); tbrp1.timeBasedFileNamingAndTriggeringPolicy.setCurrentTime(currentTime); for (int i = 0; i < 3; i++) { rfa1.doAppend("Hello---" + i); addExpectedFileNamedIfItsTime_ByDate(fileNamePatternStr); incCurrentTime(500); tbrp1.timeBasedFileNamingAndTriggeringPolicy.setCurrentTime(currentTime); add(tbrp1.compressionFuture); add(tbrp1.cleanUpFuture); } rfa1.stop(); waitForJobsToComplete(); if (waitDuration != NO_RESTART) { doRestart(testId, patternPrefix, fileOptionIsSet, waitDuration); } waitForJobsToComplete(); massageExpectedFilesToCorresponToCurrentTarget(fileName, fileOptionIsSet); StatusPrinter.print(context); rolloverChecker.check(expectedFilenameList); }