Search in sources :

Example 1 with ObjectRenderer

use of org.apache.log4j.or.ObjectRenderer in project logging-log4j2 by apache.

the class Category method get.

private <T> ObjectRenderer get(final Class<T> clazz) {
    ObjectRenderer renderer = null;
    for (Class<? super T> c = clazz; c != null; c = c.getSuperclass()) {
        renderer = rendererMap.get(c);
        if (renderer != null) {
            return renderer;
        }
        renderer = searchInterfaces(c);
        if (renderer != null) {
            return renderer;
        }
    }
    return null;
}
Also used : ObjectRenderer(org.apache.log4j.or.ObjectRenderer)

Example 2 with ObjectRenderer

use of org.apache.log4j.or.ObjectRenderer in project logging-log4j2 by apache.

the class Category method searchInterfaces.

ObjectRenderer searchInterfaces(final Class<?> c) {
    ObjectRenderer renderer = rendererMap.get(c);
    if (renderer != null) {
        return renderer;
    }
    final Class<?>[] ia = c.getInterfaces();
    for (final Class<?> clazz : ia) {
        renderer = searchInterfaces(clazz);
        if (renderer != null) {
            return renderer;
        }
    }
    return null;
}
Also used : ObjectRenderer(org.apache.log4j.or.ObjectRenderer)

Example 3 with ObjectRenderer

use of org.apache.log4j.or.ObjectRenderer in project logging-log4j2 by apache.

the class Category method forcedLog.

public void forcedLog(final String fqcn, final Priority level, final Object message, final Throwable t) {
    final org.apache.logging.log4j.Level lvl = org.apache.logging.log4j.Level.toLevel(level.toString());
    if (logger instanceof ExtendedLogger) {
        @SuppressWarnings("unchecked") final Message msg = message instanceof Message ? (Message) message : message instanceof Map ? new MapMessage((Map) message) : new ObjectMessage(message);
        ((ExtendedLogger) logger).logMessage(fqcn, lvl, null, msg, t);
    } else {
        final ObjectRenderer renderer = get(message.getClass());
        final Message msg = message instanceof Message ? (Message) message : renderer != null ? new RenderedMessage(renderer, message) : new ObjectMessage(message);
        logger.log(lvl, msg, t);
    }
}
Also used : ExtendedLogger(org.apache.logging.log4j.spi.ExtendedLogger) SimpleMessage(org.apache.logging.log4j.message.SimpleMessage) ObjectMessage(org.apache.logging.log4j.message.ObjectMessage) MapMessage(org.apache.logging.log4j.message.MapMessage) Message(org.apache.logging.log4j.message.Message) LocalizedMessage(org.apache.logging.log4j.message.LocalizedMessage) ObjectRenderer(org.apache.log4j.or.ObjectRenderer) ObjectMessage(org.apache.logging.log4j.message.ObjectMessage) MapMessage(org.apache.logging.log4j.message.MapMessage) RendererMap(org.apache.log4j.or.RendererMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) Map(java.util.Map)

Aggregations

ObjectRenderer (org.apache.log4j.or.ObjectRenderer)3 Map (java.util.Map)1 ConcurrentMap (java.util.concurrent.ConcurrentMap)1 RendererMap (org.apache.log4j.or.RendererMap)1 LocalizedMessage (org.apache.logging.log4j.message.LocalizedMessage)1 MapMessage (org.apache.logging.log4j.message.MapMessage)1 Message (org.apache.logging.log4j.message.Message)1 ObjectMessage (org.apache.logging.log4j.message.ObjectMessage)1 SimpleMessage (org.apache.logging.log4j.message.SimpleMessage)1 ExtendedLogger (org.apache.logging.log4j.spi.ExtendedLogger)1