Search in sources :

Example 36 with Log4jLogEvent

use of org.apache.logging.log4j.core.impl.Log4jLogEvent in project logging-log4j2 by apache.

the class Log4jLogEventBenchmark method createSerializableLogEventProxyWithoutExceptionWithLocation.

@Benchmark
public Serializable createSerializableLogEventProxyWithoutExceptionWithLocation(final Blackhole bh) {
    final Log4jLogEvent event = new Log4jLogEvent("a.b.c", null, "a.b.c", Level.INFO, MESSAGE, null, null);
    final Serializable obj = Log4jLogEvent.serialize(event, true);
    bh.consume(obj);
    return obj;
}
Also used : Serializable(java.io.Serializable) Log4jLogEvent(org.apache.logging.log4j.core.impl.Log4jLogEvent) Benchmark(org.openjdk.jmh.annotations.Benchmark)

Example 37 with Log4jLogEvent

use of org.apache.logging.log4j.core.impl.Log4jLogEvent in project iaf by ibissource.

the class IbisMaskingLayout method updateLogEventMessage.

/**
 * When converting from a (Log4jLogEvent) to a mutable LogEvent ensure to not invoke any getters but assign the fields directly.
 * @see "https://issues.apache.org/jira/browse/LOG4J2-1179"
 * @see "https://issues.apache.org/jira/browse/LOG4J2-1382"
 *
 * Directly calling RewriteAppender.append(LogEvent) can do 44 million ops/sec, but when calling rewriteLogger.debug(msg) to invoke
 * a logger that calls this appender, all of a sudden throughput drops to 37 thousand ops/sec. That's 1000x slower.
 *
 * Rewriting the event ({@link MutableLogEvent#initFrom(LogEvent)}) includes invoking caller location information, {@link LogEvent#getSource()}
 * This is done by taking a snapshot of the stack and walking it, @see {@link StackLocatorUtil#calcLocation(String)}).
 * Hence avoid this at all costs, fixed from version 2.6 (LOG4J2-1382) use a builder instance to update the @{link Message}.
 */
private LogEvent updateLogEventMessage(LogEvent event, Message message) {
    if (event instanceof Log4jLogEvent) {
        Log4jLogEvent.Builder builder = ((Log4jLogEvent) event).asBuilder();
        builder.setMessage(message);
        return builder.build();
    }
    // NB: this might trigger a source location lookup.
    MutableLogEvent mutable = new MutableLogEvent();
    mutable.initFrom(event);
    mutable.setMessage(message);
    return mutable;
}
Also used : Log4jLogEvent(org.apache.logging.log4j.core.impl.Log4jLogEvent) MutableLogEvent(org.apache.logging.log4j.core.impl.MutableLogEvent)

Aggregations

Log4jLogEvent (org.apache.logging.log4j.core.impl.Log4jLogEvent)37 SimpleMessage (org.apache.logging.log4j.message.SimpleMessage)15 Test (org.junit.Test)15 AbstractJacksonLayout (org.apache.logging.log4j.jackson.AbstractJacksonLayout)14 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)6 MutableLogEvent (org.apache.logging.log4j.core.impl.MutableLogEvent)5 Log4jJsonObjectMapper (org.apache.logging.log4j.jackson.json.Log4jJsonObjectMapper)5 KeyValuePair (org.apache.logging.log4j.core.util.KeyValuePair)4 ParameterizedMessage (org.apache.logging.log4j.message.ParameterizedMessage)4 StringMap (org.apache.logging.log4j.util.StringMap)4 Serializable (java.io.Serializable)3 ThrowableProxy (org.apache.logging.log4j.core.impl.ThrowableProxy)3 Message (org.apache.logging.log4j.message.Message)3 ObjectMessage (org.apache.logging.log4j.message.ObjectMessage)3 Test (org.junit.jupiter.api.Test)3 Benchmark (org.openjdk.jmh.annotations.Benchmark)3 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2 Marker (org.apache.logging.log4j.Marker)2 Log4jJsonObjectMapper (org.apache.logging.log4j.core.jackson.Log4jJsonObjectMapper)2