mirror of
https://github.com/Febbweiss/logstash-forwarder-java.git
synced 2026-03-04 22:25:39 +00:00
Implemented tail option.
This commit is contained in:
2
pom.xml
2
pom.xml
@@ -3,7 +3,7 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>logstash-forwarder-java</groupId>
|
||||
<artifactId>logstash-forwarder-java</artifactId>
|
||||
<version>0.1.2</version>
|
||||
<version>0.1.3-SNAPSHOT</version>
|
||||
<name>logstash-forwarder-java</name>
|
||||
<description>Java version of logstash forwarder</description>
|
||||
<url>https://github.com/didfet/logstash-forwarder-java</url>
|
||||
|
||||
@@ -43,6 +43,7 @@ public class FileWatcher {
|
||||
private Map<File,FileState> newWatchMap = new HashMap<File,FileState>();
|
||||
private FileState[] savedStates;
|
||||
private int maxSignatureLength;
|
||||
private boolean tail = false;
|
||||
|
||||
public FileWatcher() {
|
||||
try {
|
||||
@@ -60,6 +61,13 @@ public class FileWatcher {
|
||||
}
|
||||
}
|
||||
processModifications();
|
||||
if(tail) {
|
||||
for(FileState state : oldWatchMap.values()) {
|
||||
if(state.getPointer() == 0) {
|
||||
state.setPointer(state.getSize());
|
||||
}
|
||||
}
|
||||
}
|
||||
printWatchMap();
|
||||
}
|
||||
|
||||
@@ -324,4 +332,8 @@ public class FileWatcher {
|
||||
this.maxSignatureLength = maxSignatureLength;
|
||||
}
|
||||
|
||||
public void setTail(boolean tail) {
|
||||
this.tail = tail;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -53,6 +53,7 @@ public class Forwarder {
|
||||
private static ProtocolAdapter adapter;
|
||||
private static Random random = new Random();
|
||||
private static int signatureLength = 4096;
|
||||
private static boolean tailSelected = false;
|
||||
|
||||
public static void main(String[] args) {
|
||||
try {
|
||||
@@ -64,6 +65,7 @@ public class Forwarder {
|
||||
// Logger.getLogger(FileReader.class).setAdditivity(false);
|
||||
watcher = new FileWatcher();
|
||||
watcher.setMaxSignatureLength(signatureLength);
|
||||
watcher.setTail(tailSelected);
|
||||
configManager = new ConfigurationManager(config);
|
||||
configManager.readConfiguration();
|
||||
for(FilesSection files : configManager.getConfig().getFiles()) {
|
||||
@@ -117,6 +119,7 @@ public class Forwarder {
|
||||
Option quiet = new Option("quiet", "operate in quiet mode - only emit errors to log");
|
||||
Option debug = new Option("debug", "operate in debug mode");
|
||||
Option trace = new Option("trace", "operate in trace mode");
|
||||
Option tail = new Option("tail", "read new files from the end");
|
||||
|
||||
Option spoolSizeOption = OptionBuilder.withArgName("number of events")
|
||||
.hasArg()
|
||||
@@ -142,6 +145,7 @@ public class Forwarder {
|
||||
.addOption(quiet)
|
||||
.addOption(debug)
|
||||
.addOption(trace)
|
||||
.addOption(tail)
|
||||
.addOption(signatureLengthOption)
|
||||
.addOption(configOption);
|
||||
CommandLineParser parser = new GnuParser();
|
||||
@@ -168,6 +172,9 @@ public class Forwarder {
|
||||
if(line.hasOption("trace")) {
|
||||
logLevel = TRACE;
|
||||
}
|
||||
if(line.hasOption("tail")) {
|
||||
tailSelected = true;
|
||||
}
|
||||
} catch(ParseException e) {
|
||||
printHelp(options);
|
||||
System.exit(1);;
|
||||
|
||||
Reference in New Issue
Block a user