Search in sources :

Example 1 with PaxLocationInfo

use of org.ops4j.pax.logging.spi.PaxLocationInfo in project fabric8 by jboss-fuse.

the class Logs method newInstance.

public static LogEvent newInstance(PaxLoggingEvent event) {
    LogEvent answer = new LogEvent();
    try {
        answer.setLevel(toString(event.getLevel()));
    } catch (NoClassDefFoundError error) {
        // ENTESB-2234, KARAF-3350: Ignore NoClassDefFoundError exceptions
        // Those exceptions may happen if the underlying pax-logging service
        // bundle has been refreshed somehow.
        answer.setLevel("LOG");
    }
    answer.setMessage(event.getMessage());
    answer.setLogger(event.getLoggerName());
    answer.setTimestamp(new Date(event.getTimeStamp()));
    answer.setThread(event.getThreadName());
    answer.setException(addMavenCoord(event.getThrowableStrRep()));
    Map eventProperties = event.getProperties();
    if (eventProperties != null && eventProperties.size() > 0) {
        Map<String, String> properties = new HashMap<String, String>();
        Set<Map.Entry> set = eventProperties.entrySet();
        for (Map.Entry entry : set) {
            Object key = entry.getKey();
            Object value = entry.getValue();
            if (key != null && value != null) {
                properties.put(toString(key), toString(value));
            }
        }
        MavenCoordinates.addMavenCoord(properties);
        answer.setProperties(properties);
    }
    // event.getFQNOfLoggerClass()
    try {
        PaxLocationInfo locationInformation = event.getLocationInformation();
        if (locationInformation != null) {
            answer.setClassName(locationInformation.getClassName());
            answer.setFileName(locationInformation.getFileName());
            answer.setMethodName(locationInformation.getMethodName());
            answer.setLineNumber(locationInformation.getLineNumber());
        }
    } catch (NoClassDefFoundError error) {
    // ENTESB-2234, KARAF-3350: Ignore NoClassDefFoundError exceptions
    }
    return answer;
}
Also used : LogEvent(io.fabric8.insight.log.LogEvent) HashMap(java.util.HashMap) PaxLocationInfo(org.ops4j.pax.logging.spi.PaxLocationInfo) HashMap(java.util.HashMap) Map(java.util.Map) Date(java.util.Date)

Aggregations

LogEvent (io.fabric8.insight.log.LogEvent)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 PaxLocationInfo (org.ops4j.pax.logging.spi.PaxLocationInfo)1