Search in sources :

Example 6 with AndFilter

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);
    }
}
Also used : AndFilter(co.cask.cdap.logging.filter.AndFilter) Filter(co.cask.cdap.logging.filter.Filter) AndFilter(co.cask.cdap.logging.filter.AndFilter) LogLocation(co.cask.cdap.logging.write.LogLocation)

Aggregations

AndFilter (co.cask.cdap.logging.filter.AndFilter)6 Filter (co.cask.cdap.logging.filter.Filter)6 LogLocation (co.cask.cdap.logging.write.LogLocation)3 IOException (java.io.IOException)3 KafkaConsumer (co.cask.cdap.logging.kafka.KafkaConsumer)2 AbstractCloseableIterator (co.cask.cdap.api.dataset.lib.AbstractCloseableIterator)1 CloseableIterator (co.cask.cdap.api.dataset.lib.CloseableIterator)1 ApplicationLoggingContext (co.cask.cdap.common.logging.ApplicationLoggingContext)1 ComponentLoggingContext (co.cask.cdap.common.logging.ComponentLoggingContext)1 LoggingContext (co.cask.cdap.common.logging.LoggingContext)1 NamespaceLoggingContext (co.cask.cdap.common.logging.NamespaceLoggingContext)1 ServiceLoggingContext (co.cask.cdap.common.logging.ServiceLoggingContext)1 MdcExpression (co.cask.cdap.logging.filter.MdcExpression)1 OrFilter (co.cask.cdap.logging.filter.OrFilter)1 ImmutableList (com.google.common.collect.ImmutableList)1 Collection (java.util.Collection)1