use of io.cdap.cdap.logging.filter.Filter in project cdap by caskdata.
the class FileLogReader method getLog.
@Override
public CloseableIterator<LogEvent> getLog(LoggingContext loggingContext, final long fromTimeMs, final long toTimeMs, Filter filter) {
try {
final Filter logFilter = new AndFilter(ImmutableList.of(LoggingContextHelper.createFilter(loggingContext), filter));
LOG.trace("Using fromTimeMs={}, toTimeMs={}", fromTimeMs, toTimeMs);
List<LogLocation> sortedFilesInRange = fileMetadataReader.listFiles(LoggingContextHelper.getLogPathIdentifier(loggingContext), fromTimeMs, toTimeMs);
if (sortedFilesInRange.isEmpty()) {
// return empty iterator
return new AbstractCloseableIterator<LogEvent>() {
@Override
protected LogEvent computeNext() {
return endOfData();
}
@Override
public void close() {
// no-op
}
};
}
final Iterator<LogLocation> filesIter = sortedFilesInRange.iterator();
CloseableIterator<CloseableIterator<LogEvent>> closeableIterator = new CloseableIterator<CloseableIterator<LogEvent>>() {
private CloseableIterator<LogEvent> curr = null;
@Override
public void close() {
if (curr != null) {
curr.close();
}
}
@Override
public boolean hasNext() {
return filesIter.hasNext();
}
@Override
public CloseableIterator<LogEvent> next() {
if (curr != null) {
curr.close();
}
LogLocation file = filesIter.next();
LOG.trace("Reading file {}", file);
curr = file.readLog(logFilter, fromTimeMs, toTimeMs, Integer.MAX_VALUE);
return curr;
}
@Override
public void remove() {
throw new UnsupportedOperationException("Remove not supported");
}
};
return concat(closeableIterator);
} catch (Throwable e) {
LOG.error("Got exception: ", e);
throw Throwables.propagate(e);
}
}
use of io.cdap.cdap.logging.filter.Filter 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