mirror of
https://github.com/Febbweiss/logstash-forwarder-java.git
synced 2026-03-04 14:15:42 +00:00
Log file rename.
This commit is contained in:
@@ -179,6 +179,10 @@ public class FileWatcher {
|
||||
logger.trace("File has been truncated or created, not retrieving pointer");
|
||||
} else {
|
||||
logger.trace("File has not been truncated or created, retrieving pointer");
|
||||
if(logger.isInfoEnabled() && ! state.getFileName().equals(oldState.getFileName()))
|
||||
{
|
||||
logger.info("File rename was detected: " + oldState.getFile() + " -> " + state.getFile());
|
||||
}
|
||||
state.setPointer(oldState.getPointer());
|
||||
state.deleteOldFileState();
|
||||
}
|
||||
|
||||
@@ -56,6 +56,10 @@ public class FileWatcherTest {
|
||||
|
||||
@Test
|
||||
public void testWildcardWatch() throws InterruptedException, IOException {
|
||||
if(System.getProperty("os.name").toLowerCase().contains("win")) {
|
||||
logger.warn("Not executing this test on windows");
|
||||
return;
|
||||
}
|
||||
FileWatcher watcher = new FileWatcher();
|
||||
watcher.addFilesToWatch("./testFileWatcher*.txt", new Event().addField("test", "test"), FileWatcher.ONE_DAY);
|
||||
watcher.initialize();
|
||||
@@ -74,21 +78,21 @@ public class FileWatcherTest {
|
||||
Thread.sleep(100);
|
||||
watcher.checkFiles();
|
||||
FileUtils.write(file1, "file 1 line 2\n", true);
|
||||
FileUtils.write(file2, "file 2 line 1\n", true);
|
||||
//FileUtils.write(file2, "file 2 line 1\n", true);
|
||||
Thread.sleep(1000);
|
||||
watcher.checkFiles();
|
||||
// FileUtils.moveFileToDirectory(file1, testDir, true);
|
||||
// FileUtils.write(file2, "file 2 line 2\n", true);
|
||||
// FileUtils.moveFile(file2, file1);
|
||||
FileUtils.moveFile(file1, file2);
|
||||
// FileUtils.write(file2, "file 3 line 1\n", true);
|
||||
//
|
||||
// Thread.sleep(1000);
|
||||
// watcher.checkFiles();
|
||||
Thread.sleep(1000);
|
||||
watcher.checkFiles();
|
||||
//
|
||||
//
|
||||
// watcher.close();
|
||||
// FileUtils.forceDelete(file1);
|
||||
// FileUtils.forceDelete(file2);
|
||||
watcher.close();
|
||||
FileUtils.deleteQuietly(file1);
|
||||
FileUtils.deleteQuietly(file2);
|
||||
// FileUtils.forceDelete(testDir);
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user