use of co.cask.cdap.logging.filter.AndFilter in project cdap by caskdata.
the class FileLogReader method getLogNext.
@Override
public void getLogNext(final LoggingContext loggingContext, final ReadRange readRange, final int maxEvents, final Filter filter, final Callback callback) {
if (readRange == ReadRange.LATEST) {
getLogPrev(loggingContext, readRange, maxEvents, filter, callback);
return;
}
callback.init();
try {
Filter logFilter = new AndFilter(ImmutableList.of(LoggingContextHelper.createFilter(loggingContext), filter));
long fromTimeMs = readRange.getFromMillis() + 1;
LOG.trace("Using fromTimeMs={}, readRange={}", fromTimeMs, readRange);
List<LogLocation> sortedFilesInRange = fileMetadataReader.listFiles(LoggingContextHelper.getLogPathIdentifier(loggingContext), readRange.getFromMillis(), readRange.getToMillis());
if (sortedFilesInRange.isEmpty()) {
return;
}
for (LogLocation file : sortedFilesInRange) {
LOG.trace("Reading file {}", file);
file.readLog(logFilter, fromTimeMs, Long.MAX_VALUE, maxEvents - callback.getCount(), callback);
if (callback.getCount() >= maxEvents) {
break;
}
}
} catch (Throwable e) {
LOG.error("Got exception: ", e);
throw Throwables.propagate(e);
}
}
Aggregations