This commit is contained in:
didfet
2015-10-30 18:22:22 +01:00
parent 5443fdee69
commit f9eadf5fb4
3 changed files with 20 additions and 11 deletions

View File

@@ -46,11 +46,12 @@ public class FileWatcher {
private boolean tail = false;
private Event stdinFields;
private boolean stdinConfigured = false;
private String sincedbFile = null;
public FileWatcher() {
try {
logger.debug("Loading saved states");
savedStates = Registrar.readStateFromJson();
savedStates = Registrar.readStateFromJson(sincedbFile);
} catch(Exception e) {
logger.warn("Could not load saved states : " + e.getMessage());
}
@@ -103,7 +104,7 @@ public class FileWatcher {
logger.trace("Reading files");
logger.trace("==============");
int numberOfLinesRead = reader.readFiles(oldWatchMap.values());
Registrar.writeStateToJson(oldWatchMap.values());
Registrar.writeStateToJson(sincedbFile,oldWatchMap.values());
return numberOfLinesRead;
}
@@ -363,4 +364,8 @@ public class FileWatcher {
this.tail = tail;
}
public void setSincedb(String sincedbFile) {
this.sincedbFile = sincedbFile;
}
}

View File

@@ -47,6 +47,7 @@ import org.apache.log4j.RollingFileAppender;
import org.apache.log4j.spi.RootLogger;
public class Forwarder {
private static final String SINCEDB = ".logstash-forwarder-java";
private static Logger logger = Logger.getLogger(Forwarder.class);
private static int spoolSize = 1024;
private static int idleTimeout = 5000;
@@ -65,6 +66,7 @@ public class Forwarder {
private static String logfile = null;
private static String logfileSize = "10MB";
private static int logfileNumber = 5;
private static String sincedbFile = SINCEDB;
public static void main(String[] args) {
try {
@@ -73,6 +75,7 @@ public class Forwarder {
watcher = new FileWatcher();
watcher.setMaxSignatureLength(signatureLength);
watcher.setTail(tailSelected);
watcher.setSincedb(sincedbFile);
configManager = new ConfigurationManager(config);
configManager.readConfiguration();
for(FilesSection files : configManager.getConfig().getFiles()) {
@@ -181,6 +184,10 @@ public class Forwarder {
.hasArg()
.withDescription("Number of logfiles (default 5)")
.create("logfilenumber");
Option sincedbOption = OptionBuilder.withArgName("sincedb file")
.hasArg()
.withDescription("Sincedb file name")
.create("sincedb");
options.addOption(helpOption)
.addOption(idleTimeoutOption)
@@ -194,7 +201,8 @@ public class Forwarder {
.addOption(configOption)
.addOption(logfileOption)
.addOption(logfileNumberOption)
.addOption(logfileSizeOption);
.addOption(logfileSizeOption)
.addOption(sincedbOption);
CommandLineParser parser = new GnuParser();
try {
@@ -235,6 +243,9 @@ public class Forwarder {
if(line.hasOption("logfilenumber")) {
logfileNumber = Integer.parseInt(line.getOptionValue("logfilenumber"));
}
if(line.hasOption("sincedb")) {
sincedbFile = line.getOptionValue("sincedb");
}
} catch(ParseException e) {
printHelp(options);
System.exit(1);;

View File

@@ -27,7 +27,7 @@ import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.ObjectMapper;
public class Registrar {
private static final String SINCEDB = ".logstash-forwarder-java";
private static ObjectMapper mapper = new ObjectMapper();
@@ -40,10 +40,6 @@ public class Registrar {
return readStateFromJson(new File(file));
}
public static FileState[] readStateFromJson() throws JsonParseException, JsonMappingException, IOException {
return readStateFromJson(SINCEDB);
}
public static void writeStateToJson(File file, Collection<FileState> stateList) throws JsonGenerationException, JsonMappingException, IOException {
mapper.writeValue(file, stateList);
}
@@ -52,7 +48,4 @@ public class Registrar {
writeStateToJson(new File(file), stateList);
}
public static void writeStateToJson(Collection<FileState> stateList) throws JsonGenerationException, JsonMappingException, IOException {
writeStateToJson(SINCEDB, stateList);
}
}