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;
}
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;
}
Aggregations