use of io.fabric8.insight.log.LogResults in project fabric8 by jboss-fuse.
the class Log4jLogQuery method filterLogResults.
protected LogResults filterLogResults(Predicate<LogEvent> predicate, int maxCount) {
int matched = 0;
long from = Long.MAX_VALUE;
long to = Long.MIN_VALUE;
List<LogEvent> list = new ArrayList<LogEvent>();
Iterable<LoggingEvent> elements = getEvents().getElements();
for (LoggingEvent element : elements) {
LogEvent logEvent = toLogEvent(element);
long timestamp = element.getTimeStamp();
if (timestamp > to) {
to = timestamp;
}
if (timestamp < from) {
from = timestamp;
}
if (logEvent != null) {
if (predicate == null || predicate.matches(logEvent)) {
list.add(logEvent);
matched += 1;
if (maxCount > 0 && matched >= maxCount) {
break;
}
}
}
}
LogResults results = new LogResults();
results.setEvents(list);
if (from < Long.MAX_VALUE) {
results.setFromTimestamp(from);
}
if (to > Long.MIN_VALUE) {
results.setToTimestamp(to);
}
if (LOG.isDebugEnabled()) {
LOG.debug("Requested " + maxCount + " logging items. returning " + results.getEvents().size() + " event(s) from a possible " + getEvents().size());
}
return results;
}
use of io.fabric8.insight.log.LogResults in project fabric8 by jboss-fuse.
the class Log4jTest method assertLogQuery.
protected void assertLogQuery(LogQuerySupportMBean mBean) throws Exception {
LogResults results = mBean.allLogResults();
List<LogEvent> logEvents = assertNotEmpty(results);
assertMatches(logEvents, messagePredicate("INFO", info1));
assertMatches(logEvents, messagePredicate("INFO", info2));
assertMatches(logEvents, messagePredicate("ERROR", error1));
assertMatches(logEvents, messagePredicate("ERROR", error2));
// test a filter
LogFilter filter = new LogFilter();
filter.setLevels(new String[] { "ERROR" });
logEvents = assertNotEmpty(mBean.queryLogResults(filter));
assertMatches(logEvents, messagePredicate("ERROR", error1));
assertMatches(logEvents, messagePredicate("ERROR", error2));
assertNotMatches(logEvents, messagePredicate("INFO", info1));
assertNotMatches(logEvents, messagePredicate("INFO", info2));
}
use of io.fabric8.insight.log.LogResults in project fabric8 by jboss-fuse.
the class LogQuerySupport method logResultsSince.
@Override
public LogResults logResultsSince(long time) throws IOException {
LogFilter filter = new LogFilter();
filter.setAfterTimestamp(time);
return queryLogResults(filter);
}
use of io.fabric8.insight.log.LogResults in project fabric8 by jboss-fuse.
the class ExceptionMavenCoordsTest method testQueryOfLogMessages.
@Test
public void testQueryOfLogMessages() throws Exception {
Logger testLog = LoggerFactory.getLogger("io.fabric8.insight.log.log4j.TestLogger");
// now lets force an exception with a stack trace from camel...
try {
CamelContextHelper.getMandatoryEndpoint(null, null);
} catch (Throwable e) {
testLog.error("Expected exception for testing: " + e, e);
}
// now lets find the error
LogResults results = logQuery.allLogResults();
List<LogEvent> logEvents = Log4jTest.assertNotEmpty(results);
LogEvent log = logEvents.get(0);
assertNotNull("Should have a log event", log);
List<String> list = Arrays.asList(log.getException());
assertTrue("Should have more than 1 items in the stack trace but got: " + list, list.size() > 1);
String first = list.get(1);
LOG.info("First line: " + first);
String expects = "[org.apache.camel:camel-core:";
assertTrue("Should have camel coordinate '" + expects + "' but got " + first, first.indexOf(expects) > 0);
for (String line : list) {
LOG.info(line);
}
}
use of io.fabric8.insight.log.LogResults 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;
}
Aggregations