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