RollingFileWriter extends AbstractFormatPatternWriter { @Override public void close() throws IOException, InterruptedException { if (writingThread) { internalClose(); } else { synchronized (writer) { internalClose(); } } } RollingFileWriter();  RollingFileWriter(final Map<String, String> properties); @Override void write(final LogEntry logEntry); @Override void flush(); @Override void close();  }
@Test public void keepAllBackups() throws IOException, InterruptedException { File file1 = folder.newFile("0"); File file2 = folder.newFile("1"); File file3 = folder.newFile("2"); File file4 = folder.newFile("3"); file1.setLastModified(0); file2.setLastModified(1000); file3.setLastModified(2000); file4.setLastModified(3000); Map<String, String> properties = new HashMap<>(); properties.put("file", new File(folder.getRoot(), "{count}").getAbsolutePath()); properties.put("format", "{message}"); properties.put("policies", "size: 1MB"); properties.put("backups", "-1"); RollingFileWriter writer = new RollingFileWriter(properties); try { assertThat(file1).exists(); assertThat(file2).exists(); assertThat(file3).exists(); assertThat(file4).exists(); } finally { writer.close(); } }
@Test public void deleteBackupsAtStartUp() throws IOException, InterruptedException { File file1 = folder.newFile("0"); File file2 = folder.newFile("1"); File file3 = folder.newFile("2"); file1.setLastModified(0); file2.setLastModified(1000); file3.setLastModified(2000); Map<String, String> properties = new HashMap<>(); properties.put("file", new File(folder.getRoot(), "{count}").getAbsolutePath()); properties.put("format", "{message}"); properties.put("policies", "size: 1MB"); properties.put("backups", "2"); RollingFileWriter writer = new RollingFileWriter(properties); try { assertThat(file1).doesNotExist(); assertThat(file2).exists(); assertThat(file3).exists(); } finally { writer.close(); } }
@Test public void invalidCharset() throws IOException, InterruptedException { String file = FileSystem.createTemporaryFile(); new RollingFileWriter(doubletonMap("file", file, "charset", "UTF-42")).close(); assertThat(systemStream.consumeErrorOutput()).containsOnlyOnce("ERROR").containsOnlyOnce("charset").containsOnlyOnce("UTF-42"); }