Class ReusableLogEventFactory
java.lang.Object
org.apache.logging.log4j.core.impl.ReusableLogEventFactory
- All Implemented Interfaces:
LocationAwareLogEventFactory,LogEventFactory
public class ReusableLogEventFactory
extends Object
implements LogEventFactory, LocationAwareLogEventFactory
Garbage-free LogEventFactory that reuses a single mutable log event.
- Since:
- 2.6
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptioncreateEvent(String loggerName, Marker marker, String fqcn, StackTraceElement location, Level level, Message message, List<Property> properties, Throwable t) Creates a log event.createEvent(String loggerName, Marker marker, String fqcn, Level level, Message message, List<Property> properties, Throwable t) Creates a log event.static voidSwitches thereservedflag off if the specified event is a MutableLogEvent, otherwise does nothing.
-
Constructor Details
-
ReusableLogEventFactory
public ReusableLogEventFactory()
-
-
Method Details
-
createEvent
public LogEvent createEvent(String loggerName, Marker marker, String fqcn, Level level, Message message, List<Property> properties, Throwable t) Creates a log event.- Specified by:
createEventin interfaceLogEventFactory- Parameters:
loggerName- The name of the Logger.marker- An optional Marker.fqcn- The fully qualified class name of the caller.level- The event Level.message- The Message.properties- Properties to be added to the log event.t- An optional Throwable.- Returns:
- The LogEvent.
-
createEvent
public LogEvent createEvent(String loggerName, Marker marker, String fqcn, StackTraceElement location, Level level, Message message, List<Property> properties, Throwable t) Creates a log event.Implementation note: This method mutates the state of the
messageparameter:-
If the message is a
ReusableMessage, this method will remove its parameter references, which prevents it from being used again. -
Otherwise the lazy
Message.getFormattedMessage()message might be called. Seelog4j2.formatMsgAsyncfor details.
- Specified by:
createEventin interfaceLocationAwareLogEventFactory- Specified by:
createEventin interfaceLogEventFactory- Parameters:
loggerName- The name of the Logger.marker- An optional Marker.fqcn- The fully qualified class name of the caller.location- The location of the caller.level- The event Level.message- The log message. The object passed will be modified by this method and should not be reused.properties- Properties to be added to the log event.t- An optional Throwable.- Returns:
- The LogEvent.
-
If the message is a
-
release
Switches thereservedflag off if the specified event is a MutableLogEvent, otherwise does nothing. This flag is used internally to verify that a reusable log event is no longer in use and can be reused.- Parameters:
logEvent- the log event to make available again- Since:
- 2.7
-