public interface LogEvent extends Serializable
Serializable
so that it
may be transmitted over a network connection, output in a
SerializedLayout
, and many other uses. Besides containing a
Message
, a LogEvent has a corresponding
Level
that the message was logged at. If a
Marker
was used, then it is included here. The contents of the
ThreadContext
at the time of the log call are provided via
getContextMap()
and getContextStack()
. If a Throwable
was included in the log
call, then it is provided via getThrown()
. When this class is serialized, the attached Throwable will
be wrapped into a ThrowableProxy
so that it may be safely serialized
and deserialized properly without causing problems if the exception class is not available on the other end.
Since version 2.7, getContextMap()
is deprecated in favor of getContextData()
, which
can carry both ThreadContext
data as well as other context data supplied by the
configured
ContextDataInjector
.
Modifier and Type | Method and Description |
---|---|
org.apache.logging.log4j.util.ReadOnlyStringMap |
getContextData()
Returns the
ReadOnlyStringMap object holding context data key-value pairs. |
Map<String,String> |
getContextMap()
Deprecated.
use
getContextData() instead |
org.apache.logging.log4j.ThreadContext.ContextStack |
getContextStack()
Gets the context stack (also known as Nested Diagnostic Context or NDC).
|
Instant |
getInstant()
Returns the Instant when the message was logged.
|
org.apache.logging.log4j.Level |
getLevel()
Gets the level.
|
String |
getLoggerFqcn()
Returns the fully qualified class name of the caller of the logging API.
|
String |
getLoggerName()
Gets the logger name.
|
org.apache.logging.log4j.Marker |
getMarker()
Gets the Marker associated with the event.
|
org.apache.logging.log4j.message.Message |
getMessage()
Gets the message associated with the event.
|
long |
getNanoTime()
Returns 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.
|
StackTraceElement |
getSource()
Gets the source of logging request.
|
long |
getThreadId()
Gets the thread ID.
|
String |
getThreadName()
Gets the thread name.
|
int |
getThreadPriority()
Gets the thread priority.
|
Throwable |
getThrown()
Gets throwable associated with logging request.
|
ThrowableProxy |
getThrownProxy()
Gets throwable proxy associated with logging request.
|
long |
getTimeMillis()
Gets event time in milliseconds since midnight, January 1, 1970 UTC.
|
boolean |
isEndOfBatch()
Returns
true if this event is the last one in a batch, false otherwise. |
boolean |
isIncludeLocation()
Returns whether the source of the logging request is required downstream.
|
void |
setEndOfBatch(boolean endOfBatch)
Sets whether this event is the last one in a batch.
|
void |
setIncludeLocation(boolean locationRequired)
Sets whether the source of the logging request is required downstream.
|
LogEvent |
toImmutable()
Returns an immutable version of this log event, which MAY BE a copy of this event.
|
LogEvent toImmutable()
@Deprecated Map<String,String> getContextMap()
getContextData()
insteadnull
.org.apache.logging.log4j.util.ReadOnlyStringMap getContextData()
ReadOnlyStringMap
object holding context data key-value pairs.
Context data (also known as Mapped Diagnostic Context or MDC) is data that is set by the application to be
included in all subsequent log events. The default source for context data is the ThreadContext
(and
properties
configured on the Logger that logged the event), but users can configure a custom ContextDataInjector
to inject key-value pairs from any arbitrary source.
ReadOnlyStringMap
object holding context data key-value pairsContextDataInjector
,
ThreadContext
org.apache.logging.log4j.ThreadContext.ContextStack getContextStack()
null
.String getLoggerFqcn()
org.apache.logging.log4j.Level getLevel()
String getLoggerName()
null
.org.apache.logging.log4j.Marker getMarker()
null
if no Marker was defined on this LogEventorg.apache.logging.log4j.message.Message getMessage()
long getTimeMillis()
getInstant()
to get higher precision timestamp information if available on this platform.System.currentTimeMillis()
Instant getInstant()
Caution: if this LogEvent
implementation is mutable and reused for multiple consecutive log messages,
then the Instant
object 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.
Instant
holding Instant details for this log eventStackTraceElement getSource()
String getThreadName()
long getThreadId()
int getThreadPriority()
Throwable getThrown()
Convenience method for ThrowableProxy.getThrowable();
ThrowableProxy getThrownProxy()
boolean isEndOfBatch()
true
if this event is the last one in a batch, false
otherwise. Used by asynchronous
Loggers and Appenders to signal to buffered downstream components when to flush to disk, as a more efficient
alternative to the immediateFlush=true
configuration.boolean isIncludeLocation()
StackTrace
snapshot or not before handing off this event to
another thread.true
if the source of the logging request is required downstream, false
otherwise.getSource()
void setEndOfBatch(boolean endOfBatch)
immediateFlush=true
configuration.endOfBatch
- true
if this event is the last one in a batch, false
otherwise.void setIncludeLocation(boolean locationRequired)
StackTrace
snapshot or not before handing off this event to
another thread.locationRequired
- true
if the source of the logging request is required downstream, false
otherwise.getSource()
long getNanoTime()
Copyright © 1999-2020 The Apache Software Foundation. All Rights Reserved.
Apache Logging, Apache Log4j, Log4j, Apache, the Apache feather logo, the Apache Logging project logo, and the Apache Log4j logo are trademarks of The Apache Software Foundation.