mirror of
https://github.com/Febbweiss/logstash-forwarder-java.git
synced 2026-03-04 22:25:39 +00:00
Solve #21
This commit is contained in:
@@ -52,6 +52,8 @@ public class FileState {
|
||||
private FileState oldFileState;
|
||||
@JsonIgnore
|
||||
private Event fields;
|
||||
@JsonIgnore
|
||||
private boolean matchedToNewFile = false;
|
||||
|
||||
public FileState() {
|
||||
}
|
||||
@@ -160,6 +162,7 @@ public class FileState {
|
||||
|
||||
public void setOldFileState(FileState oldFileState) {
|
||||
this.oldFileState = oldFileState;
|
||||
oldFileState.setMatchedToNewFile(true);
|
||||
}
|
||||
|
||||
public void deleteOldFileState() {
|
||||
@@ -176,6 +179,14 @@ public class FileState {
|
||||
public void setFields(Event fields) {
|
||||
this.fields = fields;
|
||||
}
|
||||
|
||||
public boolean isMatchedToNewFile() {
|
||||
return matchedToNewFile;
|
||||
}
|
||||
|
||||
public void setMatchedToNewFile(boolean matchedToNewFile) {
|
||||
this.matchedToNewFile = matchedToNewFile;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
|
||||
@@ -188,6 +188,16 @@ public class FileWatcher {
|
||||
if(logger.isDebugEnabled()) {
|
||||
logger.debug("File " + state.getFile() + " has been truncated or created, not retrieving pointer");
|
||||
}
|
||||
oldState = oldWatchMap.get(state.getFile());
|
||||
if(oldState != null && ! oldState.isMatchedToNewFile()) {
|
||||
if(logger.isDebugEnabled()) {
|
||||
logger.debug("File " + state.getFile() + " has been replaced and not renamed, removing from watchMap");
|
||||
}
|
||||
try {
|
||||
oldState.getRandomAccessFile().close();
|
||||
} catch(Exception e) {}
|
||||
oldWatchMap.remove(state.getFile());
|
||||
}
|
||||
} else {
|
||||
if(logger.isInfoEnabled() && ! state.getFileName().equals(oldState.getFileName()))
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user