mirror of
https://github.com/Febbweiss/logstash-forwarder-java.git
synced 2026-03-04 14:15:42 +00:00
Merge branch 'master' of https://github.com/toliman7/logstash-forwarder-java
# Conflicts: # src/main/java/info/fetter/logstashforwarder/FileWatcher.java # src/test/java/info/fetter/logstashforwarder/FileWatcherTest.java
This commit is contained in:
@@ -48,7 +48,8 @@ public class FileWatcher {
|
||||
private boolean stdinConfigured = false;
|
||||
private String sincedbFile = null;
|
||||
|
||||
public FileWatcher() {
|
||||
public FileWatcher(String sincedbFileName) {
|
||||
sincedbFile = sincedbFileName;
|
||||
try {
|
||||
logger.debug("Loading saved states");
|
||||
savedStates = Registrar.readStateFromJson(sincedbFile);
|
||||
@@ -76,7 +77,7 @@ public class FileWatcher {
|
||||
printWatchMap();
|
||||
}
|
||||
|
||||
public void addFilesToWatch(String fileToWatch, Event fields, int deadTime, Multiline multiline) {
|
||||
public void addFilesToWatch(String fileToWatch, Event fields, long deadTime, Multiline multiline) {
|
||||
try {
|
||||
if(fileToWatch.equals("-")) {
|
||||
addStdIn(fields);
|
||||
@@ -219,7 +220,7 @@ public class FileWatcher {
|
||||
removeMarkedFilesFromWatchMap();
|
||||
}
|
||||
|
||||
private void addSingleFile(String fileToWatch, Event fields, int deadTime, Multiline multiline) throws Exception {
|
||||
private void addSingleFile(String fileToWatch, Event fields, long deadTime, Multiline multiline) throws Exception {
|
||||
logger.info("Watching file : " + new File(fileToWatch).getCanonicalPath());
|
||||
String directory = FilenameUtils.getFullPath(fileToWatch);
|
||||
String fileName = FilenameUtils.getName(fileToWatch);
|
||||
@@ -230,7 +231,7 @@ public class FileWatcher {
|
||||
initializeWatchMap(new File(directory), fileFilter, fields, multiline);
|
||||
}
|
||||
|
||||
private void addWildCardFiles(String filesToWatch, Event fields, int deadTime, Multiline multiline) throws Exception {
|
||||
private void addWildCardFiles(String filesToWatch, Event fields, long deadTime, Multiline multiline) throws Exception {
|
||||
logger.info("Watching wildcard files : " + filesToWatch);
|
||||
String directory = FilenameUtils.getFullPath(filesToWatch);
|
||||
String wildcard = FilenameUtils.getName(filesToWatch);
|
||||
@@ -367,6 +368,5 @@ public class FileWatcher {
|
||||
|
||||
public void setSincedb(String sincedbFile) {
|
||||
this.sincedbFile = sincedbFile;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -72,10 +72,9 @@ public class Forwarder {
|
||||
try {
|
||||
parseOptions(args);
|
||||
setupLogging();
|
||||
watcher = new FileWatcher();
|
||||
watcher = new FileWatcher(sincedbFile);
|
||||
watcher.setMaxSignatureLength(signatureLength);
|
||||
watcher.setTail(tailSelected);
|
||||
watcher.setSincedb(sincedbFile);
|
||||
configManager = new ConfigurationManager(config);
|
||||
configManager.readConfiguration();
|
||||
for(FilesSection files : configManager.getConfig().getFiles()) {
|
||||
|
||||
@@ -54,8 +54,8 @@ public class FilesSection {
|
||||
return deadTime;
|
||||
}
|
||||
|
||||
public int getDeadTimeInSeconds() {
|
||||
int deadTimeInSeconds = 0;
|
||||
public long getDeadTimeInSeconds() {
|
||||
long deadTimeInSeconds = 0;
|
||||
String remaining = deadTime;
|
||||
|
||||
if(deadTime.contains("h")) {
|
||||
|
||||
@@ -48,7 +48,7 @@ public class FileWatcherTest {
|
||||
|
||||
//@Test
|
||||
public void testFileWatch() throws InterruptedException, IOException {
|
||||
FileWatcher watcher = new FileWatcher();
|
||||
FileWatcher watcher = new FileWatcher(".logstash-forwarder-java");
|
||||
watcher.addFilesToWatch("./test.txt", new Event().addField("test", "test"), FileWatcher.ONE_DAY, null);
|
||||
for(int i = 0; i < 100; i++) {
|
||||
Thread.sleep(1000);
|
||||
@@ -58,7 +58,7 @@ public class FileWatcherTest {
|
||||
|
||||
//@Test
|
||||
public void testFileWatchWithMultilines() throws InterruptedException, IOException {
|
||||
FileWatcher watcher = new FileWatcher();
|
||||
FileWatcher watcher = new FileWatcher(".logstash-forwarder-java");
|
||||
Multiline multiline = new Multiline();
|
||||
watcher.addFilesToWatch("./test.txt", new Event().addField("test", "test"), FileWatcher.ONE_DAY, multiline);
|
||||
for(int i = 0; i < 100; i++) {
|
||||
@@ -73,7 +73,7 @@ public class FileWatcherTest {
|
||||
logger.warn("Not executing this test on windows");
|
||||
return;
|
||||
}
|
||||
FileWatcher watcher = new FileWatcher();
|
||||
FileWatcher watcher = new FileWatcher(".logstash-forwarder-java");
|
||||
watcher.addFilesToWatch("./testFileWatcher*.txt", new Event().addField("test", "test"), FileWatcher.ONE_DAY, null);
|
||||
watcher.initialize();
|
||||
|
||||
@@ -118,7 +118,7 @@ public class FileWatcherTest {
|
||||
logger.warn("Not executing this test on windows");
|
||||
return;
|
||||
}
|
||||
FileWatcher watcher = new FileWatcher();
|
||||
FileWatcher watcher = new FileWatcher(".logstash-forwarder-java");
|
||||
Map<String, String> m = new HashMap<String, String>();
|
||||
m.put("pattern", " nl");
|
||||
m.put("negate", "false");
|
||||
|
||||
Reference in New Issue
Block a user