Search in sources :

Example 6 with LogEvent

use of io.fabric8.insight.log.LogEvent 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);
    }
}
Also used : LogResults(io.fabric8.insight.log.LogResults) LogEvent(io.fabric8.insight.log.LogEvent) Logger(org.slf4j.Logger) Test(org.junit.Test)

Aggregations

LogEvent (io.fabric8.insight.log.LogEvent)6 LogResults (io.fabric8.insight.log.LogResults)3 Date (java.util.Date)3 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 LogFilter (io.fabric8.insight.log.LogFilter)1 Predicate (io.fabric8.insight.log.support.Predicate)1 HashMap (java.util.HashMap)1 Category (org.apache.log4j.Category)1 Level (org.apache.log4j.Level)1 LocationInfo (org.apache.log4j.spi.LocationInfo)1 LoggingEvent (org.apache.log4j.spi.LoggingEvent)1 ThrowableInformation (org.apache.log4j.spi.ThrowableInformation)1 Test (org.junit.Test)1 PaxLocationInfo (org.ops4j.pax.logging.spi.PaxLocationInfo)1 Logger (org.slf4j.Logger)1