Class Log4jLogEvent
java.lang.Object
org.apache.logging.log4j.core.impl.Log4jLogEvent
- All Implemented Interfaces:
Serializable,LogEvent
Implementation of a LogEvent.
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classLogEvent Builder helper class.(package private) static classProxy pattern used to serialize the LogEvent. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final Clockprivate static final ContextDataInjectorprivate final StringMapprivate final ThreadContext.ContextStackprivate booleanprivate booleanprivate final MutableInstantprivate final Levelprivate final Stringprivate final Stringprivate final Markerprivate Messageprivate static NanoClockprivate final longprivate static final longprivate StackTraceElementprivate longprivate Stringprivate intprivate final Throwableprivate ThrowableProxy -
Constructor Summary
ConstructorsModifierConstructorDescriptionLog4jLogEvent(long timestamp) Deprecated.Log4jLogEvent(String loggerName, Marker marker, String loggerFQCN, StackTraceElement source, Level level, Message message, List<Property> properties, Throwable t) Constructor.Log4jLogEvent(String loggerName, Marker marker, String loggerFQCN, Level level, Message message, Throwable t) Deprecated.useLog4jLogEvent.Builderinstead.Log4jLogEvent(String loggerName, Marker marker, String loggerFQCN, Level level, Message message, Throwable t, Map<String, String> mdc, ThreadContext.ContextStack ndc, String threadName, StackTraceElement location, long timestampMillis) Deprecated.useLog4jLogEvent.Builderinstead.privateLog4jLogEvent(String loggerName, Marker marker, String loggerFQCN, Level level, Message message, Throwable thrown, ThrowableProxy thrownProxy, StringMap contextData, ThreadContext.ContextStack contextStack, long threadId, String threadName, int threadPriority, StackTraceElement source, long nanoTime) privateLog4jLogEvent(String loggerName, Marker marker, String loggerFQCN, Level level, Message message, Throwable thrown, ThrowableProxy thrownProxy, StringMap contextData, ThreadContext.ContextStack contextStack, long threadId, String threadName, int threadPriority, StackTraceElement source, long timestampMillis, int nanoOfMillisecond, long nanoTime) Constructor.privateLog4jLogEvent(String loggerName, Marker marker, String loggerFQCN, Level level, Message message, Throwable thrown, ThrowableProxy thrownProxy, StringMap contextData, ThreadContext.ContextStack contextStack, long threadId, String threadName, int threadPriority, StackTraceElement source, Clock clock, long nanoTime) Log4jLogEvent(String loggerName, Marker marker, String loggerFQCN, Level level, Message message, List<Property> properties, Throwable t) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionReturns a new fully initializedLog4jLogEvent.Buildercontaining a copy of all fields of this event.static booleancanDeserialize(Serializable event) private static StringMapcreateContextData(List<Property> properties) private static StringMapcreateContextData(Map<String, String> contextMap) static Log4jLogEventcreateEvent(String loggerName, Marker marker, String loggerFQCN, Level level, Message message, Throwable thrown, ThrowableProxy thrownProxy, Map<String, String> mdc, ThreadContext.ContextStack ndc, String threadName, StackTraceElement location, long timestamp) Deprecated.useLog4jLogEvent.Builderinstead.static LogEventcreateMemento(LogEvent logEvent) static Log4jLogEventcreateMemento(LogEvent event, boolean includeLocation) Creates and returns a new immutable copy of thisLog4jLogEvent.static Log4jLogEventdeserialize(Serializable event) booleanReturns theReadOnlyStringMapcontaining context data key-value pairs.Returns the immutable copy of the ThreadContext Map.Returns an immutable copy of the ThreadContext stack.Returns the Instant when the message was logged.getLevel()Returns the logging Level.The fully qualified class name of the class that was called by the caller.Returns the name of the Logger used to generate the event.Returns the Marker associated with the event, or null.Returns the Message associated with the event.static NanoClockReturns theNanoClockto use for creating the nanoTime timestamp of log events.longReturns the value of the running Java Virtual Machine's high-resolution time source when this event was created, or a dummy value if it is known that this value will not be used downstream.Returns the StackTraceElement for the caller.longGets the thread ID.Returns the name of the Thread on which the event was generated.intGets the thread priority.Returns the Throwable associated with the event, or null.Returns the ThrowableProxy associated with the event, or null.longGets event time in milliseconds since midnight, January 1, 1970 UTC.inthashCode()booleanReturnstrueif this event is the last one in a batch,falseotherwise.booleanReturns whether the source of the logging request is required downstream.voidstatic Log4jLogEvent.BuilderReturns a new emptyLog4jLogEvent.Builderwith all fields empty.private voidreadObject(ObjectInputStream stream) static Serializableserialize(Log4jLogEvent event, boolean includeLocation) Take a snapshot of the specifiedLog4jLogEvent.static SerializableTake a snapshot of the specifiedLogEvent.voidsetEndOfBatch(boolean endOfBatch) Sets whether this event is the last one in a batch.voidsetIncludeLocation(boolean includeLocation) Sets whether the source of the logging request is required downstream.static voidsetNanoClock(NanoClock nanoClock) Sets theNanoClockto use for creating the nanoTime timestamp of log events.Returns an immutable version of this log event, which MAY BE a copy of this event.toString()protected ObjectCreates a LogEventProxy that can be serialized.
-
Field Details
-
serialVersionUID
private static final long serialVersionUID- See Also:
-
CLOCK
-
nanoClock
-
CONTEXT_DATA_INJECTOR
-
loggerFqcn
-
marker
-
level
-
loggerName
-
message
-
instant
-
thrown
-
thrownProxy
-
contextData
-
contextStack
-
threadId
private long threadId -
threadName
-
threadPriority
private int threadPriority -
source
-
includeLocation
private boolean includeLocation -
endOfBatch
private boolean endOfBatch -
nanoTime
private final transient long nanoTime- Since:
- Log4J 2.4
-
-
Constructor Details
-
Log4jLogEvent
public Log4jLogEvent() -
Log4jLogEvent
Deprecated.useLog4jLogEvent.Builderinstead. This constructor will be removed in an upcoming release. -
Log4jLogEvent
@Deprecated public Log4jLogEvent(String loggerName, Marker marker, String loggerFQCN, Level level, Message message, Throwable t) Deprecated.useLog4jLogEvent.Builderinstead. This constructor will be removed in an upcoming release.Constructor.- Parameters:
loggerName- The name of the Logger.marker- The Marker or null.loggerFQCN- The fully qualified class name of the caller.level- The logging Level.message- The Message.t- A Throwable or null.
-
Log4jLogEvent
public Log4jLogEvent(String loggerName, Marker marker, String loggerFQCN, Level level, Message message, List<Property> properties, Throwable t) Constructor.- Parameters:
loggerName- The name of the Logger.marker- The Marker or null.loggerFQCN- The fully qualified class name of the caller.level- The logging Level.message- The Message.properties- the properties to be merged with ThreadContext key-value pairs into the event's ReadOnlyStringMap.t- A Throwable or null.
-
Log4jLogEvent
public Log4jLogEvent(String loggerName, Marker marker, String loggerFQCN, StackTraceElement source, Level level, Message message, List<Property> properties, Throwable t) Constructor.- Parameters:
loggerName- The name of the Logger.marker- The Marker or null.loggerFQCN- The fully qualified class name of the caller.level- The logging Level.message- The Message.properties- the properties to be merged with ThreadContext key-value pairs into the event's ReadOnlyStringMap.t- A Throwable or null.
-
Log4jLogEvent
@Deprecated public Log4jLogEvent(String loggerName, Marker marker, String loggerFQCN, Level level, Message message, Throwable t, Map<String, String> mdc, ThreadContext.ContextStack ndc, String threadName, StackTraceElement location, long timestampMillis) Deprecated.useLog4jLogEvent.Builderinstead. This constructor will be removed in an upcoming release.Constructor.- Parameters:
loggerName- The name of the Logger.marker- The Marker or null.loggerFQCN- The fully qualified class name of the caller.level- The logging Level.message- The Message.t- A Throwable or null.mdc- The mapped diagnostic context.ndc- the nested diagnostic context.threadName- The name of the thread.location- The locations of the caller.timestampMillis- The timestamp of the event.
-
Log4jLogEvent
private Log4jLogEvent(String loggerName, Marker marker, String loggerFQCN, Level level, Message message, Throwable thrown, ThrowableProxy thrownProxy, StringMap contextData, ThreadContext.ContextStack contextStack, long threadId, String threadName, int threadPriority, StackTraceElement source, long timestampMillis, int nanoOfMillisecond, long nanoTime) Constructor.- Parameters:
loggerName- The name of the Logger.marker- The Marker or null.loggerFQCN- The fully qualified class name of the caller.level- The logging Level.message- The Message.thrown- A Throwable or null.thrownProxy- A ThrowableProxy or null.contextData- The key-value pairs from the context.contextStack- the nested diagnostic context.threadId- the thread IDthreadName- The name of the thread.threadPriority- the thread prioritysource- The locations of the caller.timestampMillis- The timestamp of the event.nanoOfMillisecond- the nanoseconds within the millisecond, always positive, never exceeds999,999nanoTime- The value of the running Java Virtual Machine's high-resolution time source when the event was created.
-
Log4jLogEvent
private Log4jLogEvent(String loggerName, Marker marker, String loggerFQCN, Level level, Message message, Throwable thrown, ThrowableProxy thrownProxy, StringMap contextData, ThreadContext.ContextStack contextStack, long threadId, String threadName, int threadPriority, StackTraceElement source, Clock clock, long nanoTime) -
Log4jLogEvent
private Log4jLogEvent(String loggerName, Marker marker, String loggerFQCN, Level level, Message message, Throwable thrown, ThrowableProxy thrownProxy, StringMap contextData, ThreadContext.ContextStack contextStack, long threadId, String threadName, int threadPriority, StackTraceElement source, long nanoTime)
-
-
Method Details
-
newBuilder
Returns a new emptyLog4jLogEvent.Builderwith all fields empty.- Returns:
- a new empty builder.
-
createEvent
@Deprecated public static Log4jLogEvent createEvent(String loggerName, Marker marker, String loggerFQCN, Level level, Message message, Throwable thrown, ThrowableProxy thrownProxy, Map<String, String> mdc, ThreadContext.ContextStack ndc, String threadName, StackTraceElement location, long timestamp) Deprecated.useLog4jLogEvent.Builderinstead. This method will be removed in an upcoming release.Create a new LogEvent.- Parameters:
loggerName- The name of the Logger.marker- The Marker or null.loggerFQCN- The fully qualified class name of the caller.level- The logging Level.message- The Message.thrown- A Throwable or null.thrownProxy- A ThrowableProxy or null.mdc- The mapped diagnostic context.ndc- the nested diagnostic context.threadName- The name of the thread.location- The locations of the caller.timestamp- The timestamp of the event.- Returns:
- a new LogEvent
-
createContextData
-
createContextData
-
getNanoClock
Returns theNanoClockto use for creating the nanoTime timestamp of log events.- Returns:
- the
NanoClockto use for creating the nanoTime timestamp of log events
-
setNanoClock
Sets theNanoClockto use for creating the nanoTime timestamp of log events.FOR INTERNAL USE. This method may be called with a different
NanoClockimplementation when the configuration changes.- Parameters:
nanoClock- theNanoClockto use for creating the nanoTime timestamp of log events
-
asBuilder
Returns a new fully initializedLog4jLogEvent.Buildercontaining a copy of all fields of this event.- Returns:
- a new fully initialized builder.
-
toImmutable
Description copied from interface:LogEventReturns an immutable version of this log event, which MAY BE a copy of this event.- Specified by:
toImmutablein interfaceLogEvent- Returns:
- an immutable version of this log event
-
getLevel
Returns the logging Level. -
getLoggerName
Returns the name of the Logger used to generate the event.- Specified by:
getLoggerNamein interfaceLogEvent- Returns:
- The Logger name.
-
getMessage
Returns the Message associated with the event.- Specified by:
getMessagein interfaceLogEvent- Returns:
- The Message.
-
makeMessageImmutable
public void makeMessageImmutable() -
getThreadId
public long getThreadId()Description copied from interface:LogEventGets the thread ID.- Specified by:
getThreadIdin interfaceLogEvent- Returns:
- thread ID.
-
getThreadName
Returns the name of the Thread on which the event was generated.- Specified by:
getThreadNamein interfaceLogEvent- Returns:
- The name of the Thread.
-
getThreadPriority
public int getThreadPriority()Description copied from interface:LogEventGets the thread priority.- Specified by:
getThreadPriorityin interfaceLogEvent- Returns:
- thread priority.
-
getTimeMillis
public long getTimeMillis()Gets event time in milliseconds since midnight, January 1, 1970 UTC. UseLogEvent.getInstant()to get higher precision timestamp information if available on this platform.- Specified by:
getTimeMillisin interfaceLogEvent- Returns:
- the milliseconds component of this log event's timestamp
- See Also:
-
getInstant
Returns the Instant when the message was logged.Caution: if this
LogEventimplementation is mutable and reused for multiple consecutive log messages, then theInstantobject returned by this method is also mutable and reused. Client code should not keep a reference to the returned object but make a copy instead.- Specified by:
getInstantin interfaceLogEvent- Returns:
- the
Instantholding Instant details for this log event - Since:
- 2.11
-
getThrown
Returns the Throwable associated with the event, or null. -
getThrownProxy
Returns the ThrowableProxy associated with the event, or null.- Specified by:
getThrownProxyin interfaceLogEvent- Returns:
- The ThrowableProxy associated with the event.
-
getMarker
Returns the Marker associated with the event, or null. -
getLoggerFqcn
The fully qualified class name of the class that was called by the caller.- Specified by:
getLoggerFqcnin interfaceLogEvent- Returns:
- the fully qualified class name of the class that is performing logging.
-
getContextData
Returns theReadOnlyStringMapcontaining context data key-value pairs.- Specified by:
getContextDatain interfaceLogEvent- Returns:
- the
ReadOnlyStringMapcontaining context data key-value pairs - Since:
- 2.7
- See Also:
-
getContextMap
Returns the immutable copy of the ThreadContext Map.- Specified by:
getContextMapin interfaceLogEvent- Returns:
- The context Map.
-
getContextStack
Returns an immutable copy of the ThreadContext stack.- Specified by:
getContextStackin interfaceLogEvent- Returns:
- The context Stack.
-
getSource
Returns the StackTraceElement for the caller. This will be the entry that occurs right before the first occurrence of FQCN as a class name. -
isIncludeLocation
public boolean isIncludeLocation()Description copied from interface:LogEventReturns whether the source of the logging request is required downstream. Asynchronous Loggers and Appenders use this flag to determine whether to take aStackTracesnapshot or not before handing off this event to another thread.- Specified by:
isIncludeLocationin interfaceLogEvent- Returns:
trueif the source of the logging request is required downstream,falseotherwise.- See Also:
-
setIncludeLocation
public void setIncludeLocation(boolean includeLocation) Description copied from interface:LogEventSets whether the source of the logging request is required downstream. Asynchronous Loggers and Appenders use this flag to determine whether to take aStackTracesnapshot or not before handing off this event to another thread.- Specified by:
setIncludeLocationin interfaceLogEvent- Parameters:
includeLocation-trueif the source of the logging request is required downstream,falseotherwise.- See Also:
-
isEndOfBatch
public boolean isEndOfBatch()Description copied from interface:LogEventReturnstrueif this event is the last one in a batch,falseotherwise. Used by asynchronous Loggers and Appenders to signal to buffered downstream components when to flush to disk, as a more efficient alternative to theimmediateFlush=trueconfiguration.- Specified by:
isEndOfBatchin interfaceLogEvent- Returns:
- whether this event is the last one in a batch.
-
setEndOfBatch
public void setEndOfBatch(boolean endOfBatch) Description copied from interface:LogEventSets whether this event is the last one in a batch. Used by asynchronous Loggers and Appenders to signal to buffered downstream components when to flush to disk, as a more efficient alternative to theimmediateFlush=trueconfiguration.- Specified by:
setEndOfBatchin interfaceLogEvent- Parameters:
endOfBatch-trueif this event is the last one in a batch,falseotherwise.
-
getNanoTime
public long getNanoTime()Description copied from interface:LogEventReturns the value of the running Java Virtual Machine's high-resolution time source when this event was created, or a dummy value if it is known that this value will not be used downstream.- Specified by:
getNanoTimein interfaceLogEvent- Returns:
- The value of the running Java Virtual Machine's high-resolution time source when this event was created.
-
writeReplace
Creates a LogEventProxy that can be serialized.- Returns:
- a LogEventProxy.
-
serialize
Take a snapshot of the specifiedLogEvent.- Parameters:
event- the event to take a snapshot ofincludeLocation- if true, this method will obtain caller location information- Returns:
- snapshot of the event as a
Serializableobject - See Also:
-
serialize
Take a snapshot of the specifiedLog4jLogEvent.- Parameters:
event- the event to take a snapshot ofincludeLocation- if true, this method will obtain caller location information- Returns:
- snapshot of the event as a
Serializableobject - See Also:
-
canDeserialize
-
deserialize
-
readObject
- Throws:
InvalidObjectException
-
createMemento
-
createMemento
Creates and returns a new immutable copy of thisLog4jLogEvent.- Returns:
- a new immutable copy of the data in this
Log4jLogEvent
-
toString
-
equals
-
hashCode
public int hashCode()
-
Log4jLogEvent.Builderinstead.