mirror of
https://github.com/Febbweiss/logstash-forwarder-java.git
synced 2026-03-04 22:25:39 +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");
|
logger.trace("File has been truncated or created, not retrieving pointer");
|
||||||
} else {
|
} else {
|
||||||
logger.trace("File has not been truncated or created, retrieving pointer");
|
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.setPointer(oldState.getPointer());
|
||||||
state.deleteOldFileState();
|
state.deleteOldFileState();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -56,6 +56,10 @@ public class FileWatcherTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testWildcardWatch() throws InterruptedException, IOException {
|
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();
|
FileWatcher watcher = new FileWatcher();
|
||||||
watcher.addFilesToWatch("./testFileWatcher*.txt", new Event().addField("test", "test"), FileWatcher.ONE_DAY);
|
watcher.addFilesToWatch("./testFileWatcher*.txt", new Event().addField("test", "test"), FileWatcher.ONE_DAY);
|
||||||
watcher.initialize();
|
watcher.initialize();
|
||||||
@@ -74,21 +78,21 @@ public class FileWatcherTest {
|
|||||||
Thread.sleep(100);
|
Thread.sleep(100);
|
||||||
watcher.checkFiles();
|
watcher.checkFiles();
|
||||||
FileUtils.write(file1, "file 1 line 2\n", true);
|
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);
|
Thread.sleep(1000);
|
||||||
watcher.checkFiles();
|
watcher.checkFiles();
|
||||||
// FileUtils.moveFileToDirectory(file1, testDir, true);
|
// FileUtils.moveFileToDirectory(file1, testDir, true);
|
||||||
// FileUtils.write(file2, "file 2 line 2\n", 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);
|
// FileUtils.write(file2, "file 3 line 1\n", true);
|
||||||
//
|
//
|
||||||
// Thread.sleep(1000);
|
Thread.sleep(1000);
|
||||||
// watcher.checkFiles();
|
watcher.checkFiles();
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
// watcher.close();
|
watcher.close();
|
||||||
// FileUtils.forceDelete(file1);
|
FileUtils.deleteQuietly(file1);
|
||||||
// FileUtils.forceDelete(file2);
|
FileUtils.deleteQuietly(file2);
|
||||||
// FileUtils.forceDelete(testDir);
|
// FileUtils.forceDelete(testDir);
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user