public void logRotate () throws IOException { logRotate(false); }
protected void checkSize() { if (maxSize > 0) { File logFile = new File(logName); if (logFile.length() > maxSize) { try { logDebug("maxSize (" + maxSize + ") threshold reached"); logRotate(); } catch (IOException e) { e.printStackTrace(System.err); } } } }
public void run() { try { logDebug ("time exceeded - log rotated"); logRotate(); } catch (Exception e) { logDebug(e.getMessage()); } } }
private void runPostConfiguration() throws ConfigurationException { try { if (rotateOnStartup) { logRotate(rotateOnStartup); } else { openLogFile(); } } catch (IOException e) { throw new ConfigurationException (e); } timer.schedule(); } }
@Test @Ignore ("test causes problems, closes stdout") public void testLogRotateThrowsNullPointerException() throws Throwable { RotateLogListener rotateLogListener = new RotateLogListener(); try { rotateLogListener.logRotate(); fail("Expected NullPointerException to be thrown"); } catch (NullPointerException ex) { assertNull("rotateLogListener.f", rotateLogListener.f); assertNull("rotateLogListener.p", rotateLogListener.p); } }
@Test @Ignore("This feature doesn't work in Windows so we reverted the patch c94ff02f2") public void testLogRotateAbortsWhenCreatingNewFileFails() throws Exception { String logFileName = "RotateAbortsTestLog"; RotateLogListener listener = createRotateLogListenerWithIsoDateFormat(logFileName, null); listener.log(new LogEvent("Message 1")); // when: a rotation is required but a new file cannot be created logRotationTestDirectory.preventNewFileCreation(); listener.logRotate(); // then: no error should escape and the existing log file should continue being written to listener.log(new LogEvent("Message 2")); logRotationTestDirectory.allowNewFileCreation(); String logFileContents = getStringFromFile(logRotationTestDirectory.getFile(logFileName)); System.out.println("logFileContents = " + logFileContents); assertTrue("Log file should contain first message", logFileContents.contains("Message 1")); assertTrue("Log file should contain second message", logFileContents.contains("Message 2")); assertFalse("Logger element should not have been closed", logFileContents.contains("</logger>")); File archiveFile = logRotationTestDirectory.getFile(logFileName + ".1"); assertFalse("Archive file should not exist", archiveFile.exists()); }