本文整理汇总了Java中org.apache.commons.io.input.Tailer类的典型用法代码示例。如果您正苦于以下问题:Java Tailer类的具体用法?Java Tailer怎么用?Java Tailer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Tailer类属于org.apache.commons.io.input包,在下文中一共展示了Tailer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: startTailingLog
import org.apache.commons.io.input.Tailer; //导入依赖的package包/类
private void startTailingLog() {
TailerListener listener = new TailerListenerAdapter() {
@Override
public void handle(String line) {
System.out.println(testName + ": " + line);
}
};
// Tail the log
File file = new File(getBasedir() + File.separator + getLogFileName());
try {
if (file.exists()) {
file.delete();
}
file.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
Tailer tailer = new Tailer(file, listener, TAIL_DELAY_MILLIS);
Thread thread = new Thread(tailer);
thread.setDaemon(true);
thread.start();
}
示例2: registerLogFileTailThreads
import org.apache.commons.io.input.Tailer; //导入依赖的package包/类
private void registerLogFileTailThreads() throws IOException {
final Collection<String> outputFileNames = new HashSet<>();
final Collection<Appender> loggerAppenders = this.loggerContext.getConfiguration().getAppenders().values();
loggerAppenders.forEach(appender -> {
if (appender instanceof FileAppender) {
outputFileNames.add(((FileAppender) appender).getFileName());
} else if (appender instanceof RandomAccessFileAppender) {
outputFileNames.add(((RandomAccessFileAppender) appender).getFileName());
} else if (appender instanceof RollingFileAppender) {
outputFileNames.add(((RollingFileAppender) appender).getFileName());
} else if (appender instanceof MemoryMappedFileAppender) {
outputFileNames.add(((MemoryMappedFileAppender) appender).getFileName());
} else if (appender instanceof RollingRandomAccessFileAppender) {
outputFileNames.add(((RollingRandomAccessFileAppender) appender).getFileName());
}
});
outputFileNames.forEach(s -> {
final Tailer t = new Tailer(new File(s), new LogTailerListener(), 100, false, true);
final Thread thread = new Thread(t);
thread.setPriority(Thread.MIN_PRIORITY);
thread.setName(s);
thread.start();
});
}
示例3: startTailingFile
import org.apache.commons.io.input.Tailer; //导入依赖的package包/类
/**
* Starts tailing the given file, thus updating the log lines in the table.
*
* @param file
* the file to tail
*
* @throws FileNotFoundException
* if the file was not found
*/
public void startTailingFile(File file) throws FileNotFoundException {
if (!file.exists()) {
throw new FileNotFoundException(file.getAbsolutePath());
}
closeCurrentFile();
config.getState().addToRecentFiles(file.getAbsolutePath());
logTailListener = new BufferedLogTailListener(columnizer.getValue(), columnizedLogs,
config.getPreferences().getLogBufferSize());
logTailListener.skipEmptyLogsProperty().bind(config.getPreferences().skipEmptyLogsProperty());
logTailListener.limitNumberOfLogsProperty().bind(config.getPreferences().limitNumberOfLogsProperty());
logTailListener.maxNumberOfLogsProperty().bind(config.getPreferences().maxNumberOfLogsProperty());
tailer = Tailer.create(file, logTailListener, config.getPreferences().getTailingDelayInMillis());
tailingFile.set(true);
tailedFileName.set(file.getAbsolutePath());
}
示例4: CsvStreamReader
import org.apache.commons.io.input.Tailer; //导入依赖的package包/类
/**
* Creates a CsvStreamReader with supplied separator and quote char.
*
* @param source The file to an underlying CSV source
* @param separator The delimiter to use for separating entries
* @param quoteChar The character to use for quoted elements
* @param escape The character to use for escaping a separator or quote
* @param line The line number to skip for start reading
* @param strictQuotes Sets if characters outside the quotes are ignored
* @param ignoreLeadingWhiteSpace If true, parser should ignore
* white space before a quote in a field
*/
private CsvStreamReader(Source source, char separator, char quoteChar,
char escape, int line, boolean strictQuotes,
boolean ignoreLeadingWhiteSpace) {
super(new StringReader("")); // dummy call to base constructor
contentQueue = new ArrayDeque<>();
TailerListener listener = new CsvContentListener(contentQueue);
tailer = Tailer.create(source.file(), listener, DEFAULT_MONITOR_DELAY,
false, true, 4096);
this.parser = new CSVParser(separator, quoteChar, escape, strictQuotes,
ignoreLeadingWhiteSpace);
this.skipLines = line;
try {
// wait for tailer to capture data
Thread.sleep(DEFAULT_MONITOR_DELAY);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
示例5: LogTailer
import org.apache.commons.io.input.Tailer; //导入依赖的package包/类
protected LogTailer(File toRead, long timeForFileToBeCreated) throws IOException {
long requiredTime = System.currentTimeMillis() + timeForFileToBeCreated;
while ((System.currentTimeMillis() < requiredTime) && !(toRead.exists() && toRead.canRead())) {
try {
Thread.sleep(10);
} catch (InterruptedException e) {
// ignore
}
}
if (!toRead.exists() || !toRead.canRead()) {
throw new IllegalStateException("Couldn't read "+toRead.getCanonicalPath()+" in the configured timeout");
}
logger.debug("Initialising Tailer for "+toRead.getCanonicalPath());
tailer = new Tailer(toRead, this, DELAY, false);
}
示例6: testShouldBeCallListenerHandleByLogging
import org.apache.commons.io.input.Tailer; //导入依赖的package包/类
@Test
public void testShouldBeCallListenerHandleByLogging() throws Exception {
Tailer.create(TestFileLoader.load("data/tailer/test.log"), listener, 100, true);
ConcurrentTestFileWriter.writeTestData("data/tailer/test.log", "logging", 3);
Thread.sleep(300);
verify(mockCollector, times(3)).collect(anyString());
}
示例7: open
import org.apache.commons.io.input.Tailer; //导入依赖的package包/类
public void open(Map stormConf) {
fileToParseName = fileToParse.getAbsolutePath();
parsedLineQueue = new LinkedBlockingQueue<Map>(maxQueueSize);
currentLine = 0;
if (lineParser == null)
lineParser = new NoOpLogLineParser();
tailer = Tailer.create(fileToParse, this, tailerDelayMs);
log.info("Started tailing "+fileToParseName);
}
示例8: run
import org.apache.commons.io.input.Tailer; //导入依赖的package包/类
public void run() {
if (!fileToParse.isFile()) {
log.warn("Skipping " + fileToParse.getAbsolutePath() + " because it doesn't exist anymore!");
return;
}
lineNum = 0;
batchOfDocs.clear();
startMs = System.currentTimeMillis();
if (logIndexer.tail) {
tailer = new Tailer(fileToParse, this, logIndexer.tailerDelayMs);
log.info("Tailing "+fileToParse+" with delay "+logIndexer.tailerDelayMs+" ms");
logIndexer.tailerReaperBgThread.trackTailer(this);
tailer.run(); // we're already in a thread, so just delegate to run
log.info("Tailer stopped ... LogParser for " + fileName + " is done running.");
logIndexer.onFinishedParsingFile(fileName, lineNum, skippedLines, System.currentTimeMillis() - startMs);
} else {
try {
doParseFile(fileToParse);
} catch (Exception exc) {
log.error("Failed to process file '" + fileName + "' due to: " + exc, exc);
}
}
}
示例9: tail
import org.apache.commons.io.input.Tailer; //导入依赖的package包/类
public void tail(TailerListener listener) {
File file = new File(
fileLocation);
Tailer tailer = Tailer.create(file, listener, 10);
tailer.run();
}
示例10: TailService
import org.apache.commons.io.input.Tailer; //导入依赖的package包/类
@Autowired
public TailService(@Value("${geoip2.cityfile}") String cityFile,
@Value("${access.logs}") String accessLogs, EventMessenger eventMessenger) {
this.eventMessenger = eventMessenger;
String databaseFile = cityFile;
if (databaseFile != null) {
Path database = Paths.get(databaseFile);
if (Files.exists(database)) {
try {
this.reader = new DatabaseReader.Builder(database.toFile()).build();
}
catch (IOException e) {
LoggerFactory.getLogger(getClass()).error("GeoIPCityService init", e);
}
}
}
this.tailers = new ArrayList<>();
for (String logFile : accessLogs.split(",")) {
Path p = Paths.get(logFile.trim());
this.tailers.add(new Tailer(p.toFile(), new ListenerAdapter()));
}
this.executor = Executors.newFixedThreadPool(this.tailers.size());
for (Tailer tailer : this.tailers) {
this.executor.execute(tailer);
}
}
示例11: preDestroy
import org.apache.commons.io.input.Tailer; //导入依赖的package包/类
@PreDestroy
public void preDestroy() {
if (this.tailers != null) {
for (Tailer tailer : this.tailers) {
tailer.stop();
}
}
if (this.executor != null) {
this.executor.shutdown();
}
}
示例12: initNetlogTailer
import org.apache.commons.io.input.Tailer; //导入依赖的package包/类
private void initNetlogTailer() {
if (netLogTailerThread != null) {
netLogTailerThread.interrupt();
netLogTailerThread = null;
}
if (activeNetLogFile != null) {
TailerListener listener = new NetLogTailerListener();
Tailer tailer = new Tailer(activeNetLogFile, listener, 2000);
this.netLogTailerThread = new Thread(tailer);
netLogTailerThread.setDaemon(true);
netLogTailerThread.start();
}
}
示例13: getStream
import org.apache.commons.io.input.Tailer; //导入依赖的package包/类
public Observable<String> getStream(final long pollIntervalMs) {
return Observable.create(new OnSubscribeFunc<String>() {
@Override
public Subscription onSubscribe(
final Observer<? super String> observer) {
TailerListener listener = createListener(observer);
final Tailer tailer = new Tailer(file, listener, pollIntervalMs);
Thread t = new Thread(createRunnable(observer, tailer));
t.start();
return createSubscription(tailer);
}
});
}
示例14: createRunnable
import org.apache.commons.io.input.Tailer; //导入依赖的package包/类
private Runnable createRunnable(final Observer<? super String> observer,
final Tailer tailer) {
return new Runnable() {
@Override
public void run() {
try {
tailer.run();
} catch (Exception e) {
observer.onError(e);
}
}
};
}
示例15: createSubscription
import org.apache.commons.io.input.Tailer; //导入依赖的package包/类
private Subscription createSubscription(final Tailer tailer) {
return new Subscription() {
@Override
public void unsubscribe() {
tailer.stop();
}
};
}