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