mirror of
https://github.com/Febbweiss/logstash-forwarder-java.git
synced 2026-03-04 22:25:39 +00:00
Fix #18.
This commit is contained in:
@@ -80,7 +80,7 @@ public class Forwarder {
|
||||
configManager.readConfiguration();
|
||||
for(FilesSection files : configManager.getConfig().getFiles()) {
|
||||
for(String path : files.getPaths()) {
|
||||
watcher.addFilesToWatch(path, new Event(files.getFields()), FileWatcher.ONE_DAY);
|
||||
watcher.addFilesToWatch(path, new Event(files.getFields()), files.getDeadTimeInSeconds() * 1000);
|
||||
}
|
||||
}
|
||||
watcher.initialize();
|
||||
|
||||
@@ -22,9 +22,13 @@ import java.util.Map;
|
||||
|
||||
import org.apache.commons.lang.builder.ToStringBuilder;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
public class FilesSection {
|
||||
private List<String> paths;
|
||||
private Map<String,String> fields;
|
||||
@JsonProperty("dead time")
|
||||
private String deadTime = "24h";
|
||||
|
||||
public List<String> getPaths() {
|
||||
return paths;
|
||||
@@ -41,12 +45,46 @@ public class FilesSection {
|
||||
public void setFields(Map<String, String> fields) {
|
||||
this.fields = fields;
|
||||
}
|
||||
|
||||
|
||||
public String getDeadTime() {
|
||||
return deadTime;
|
||||
}
|
||||
|
||||
public int getDeadTimeInSeconds() {
|
||||
int deadTimeInSeconds = 0;
|
||||
String remaining = deadTime;
|
||||
|
||||
if(deadTime.contains("h")) {
|
||||
String[] splitByHour = deadTime.split("h",2);
|
||||
if(splitByHour.length > 1) {
|
||||
remaining = splitByHour[1];
|
||||
}
|
||||
deadTimeInSeconds += Integer.parseInt(splitByHour[0]) * 3600;
|
||||
}
|
||||
if(remaining.contains("m")) {
|
||||
String[] splitByMinute = remaining.split("m",2);
|
||||
if(splitByMinute.length > 1) {
|
||||
remaining = splitByMinute[1];
|
||||
}
|
||||
deadTimeInSeconds += Integer.parseInt(splitByMinute[0]) * 60;
|
||||
}
|
||||
if(remaining.contains("s")) {
|
||||
String[] splitBySecond = remaining.split("s",2);
|
||||
deadTimeInSeconds += Integer.parseInt(splitBySecond[0]);
|
||||
}
|
||||
return deadTimeInSeconds;
|
||||
}
|
||||
|
||||
public void setDeadTime(String deadTime) {
|
||||
this.deadTime = deadTime;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return new ToStringBuilder(this).
|
||||
append("paths", paths).
|
||||
append("fields", fields).
|
||||
toString();
|
||||
return new ToStringBuilder(this).
|
||||
append("paths", paths).
|
||||
append("fields", fields).
|
||||
append("dead time", deadTime).
|
||||
toString();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ package info.fetter.logstashforwarder.config;
|
||||
*/
|
||||
|
||||
import static org.apache.log4j.Level.DEBUG;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
@@ -51,5 +52,19 @@ public class ConfigurationManagerTest {
|
||||
ConfigurationManager manager = new ConfigurationManager(new File(ConfigurationManagerTest.class.getClassLoader().getResource("config1.json").getFile()));
|
||||
manager.readConfiguration();
|
||||
logger.debug(manager.getConfig().toString());
|
||||
for(FilesSection files : manager.getConfig().getFiles()) {
|
||||
logger.debug("File Section");
|
||||
for(String path : files.getPaths()) {
|
||||
logger.debug(" - Path : " + path);
|
||||
}
|
||||
logger.debug(" - Dead time : " + files.getDeadTimeInSeconds());
|
||||
if(files.getDeadTime().equals("24h")) {
|
||||
assertEquals(86400, files.getDeadTimeInSeconds());
|
||||
} else if(files.getDeadTime().equals("12h")) {
|
||||
assertEquals(43200, files.getDeadTimeInSeconds());
|
||||
} else if(files.getDeadTime().equals("8h32m50s")) {
|
||||
assertEquals(30770, files.getDeadTimeInSeconds());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,7 +46,14 @@
|
||||
"paths": [
|
||||
"/var/log/apache/httpd-*.log"
|
||||
],
|
||||
"fields": { "type": "apache" }
|
||||
"fields": { "type": "apache" },
|
||||
"dead time": "12h"
|
||||
}, {
|
||||
"paths": [
|
||||
"/var/log/apache/error-*.log"
|
||||
],
|
||||
"fields": { "type": "error" },
|
||||
"dead time": "8h32m50s"
|
||||
}
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user