Search in sources :

Example 1 with LruList

use of org.apache.karaf.shell.log.LruList in project fabric8 by jboss-fuse.

the class LogQuery method getLogEventList.

public LogResults getLogEventList(int count, Predicate<PaxLoggingEvent> predicate) {
    LogResults answer = new LogResults();
    answer.setHost(getHostName());
    long from = Long.MAX_VALUE;
    long to = Long.MIN_VALUE;
    if (appender != null) {
        LruList events = appender.getEvents();
        if (events != null) {
            Iterable<PaxLoggingEvent> iterable = events.getElements();
            if (iterable != null) {
                int matched = 0;
                for (PaxLoggingEvent event : iterable) {
                    if (event != null) {
                        long timestamp = event.getTimeStamp();
                        if (timestamp > to) {
                            to = timestamp;
                        }
                        if (timestamp < from) {
                            from = timestamp;
                        }
                        if (predicate == null || predicate.matches(event)) {
                            answer.addEvent(Logs.newInstance(event));
                            matched += 1;
                            if (count > 0 && matched >= count) {
                                break;
                            }
                        }
                    }
                }
            }
        }
    } else {
        LOG.warn("No VmLogAppender available!");
    }
    answer.setFromTimestamp(from);
    answer.setToTimestamp(to);
    return answer;
}
Also used : PaxLoggingEvent(org.ops4j.pax.logging.spi.PaxLoggingEvent) LogResults(io.fabric8.insight.log.LogResults) LruList(org.apache.karaf.shell.log.LruList)

Aggregations

LogResults (io.fabric8.insight.log.LogResults)1 LruList (org.apache.karaf.shell.log.LruList)1 PaxLoggingEvent (org.ops4j.pax.logging.spi.PaxLoggingEvent)1