public class Log4jLogEvent extends java.lang.Object implements LogEvent
| Modifier and Type | Class and Description |
|---|---|
static class |
Log4jLogEvent.Builder
LogEvent Builder helper class.
|
(package private) static class |
Log4jLogEvent.LogEventProxy
Proxy pattern used to serialize the LogEvent.
|
| Modifier and Type | Field and Description |
|---|---|
private static Clock |
CLOCK |
private static ContextDataInjector |
CONTEXT_DATA_INJECTOR |
private StringMap |
contextData |
private ThreadContext.ContextStack |
contextStack |
private boolean |
endOfBatch |
private boolean |
includeLocation |
private Level |
level |
private java.lang.String |
loggerFqcn |
private java.lang.String |
loggerName |
private Marker |
marker |
private Message |
message |
private static NanoClock |
nanoClock |
private long |
nanoTime |
private static long |
serialVersionUID |
private java.lang.StackTraceElement |
source |
private long |
threadId |
private java.lang.String |
threadName |
private int |
threadPriority |
private java.lang.Throwable |
thrown |
private ThrowableProxy |
thrownProxy |
private long |
timeMillis |
| Modifier | Constructor and Description |
|---|---|
|
Log4jLogEvent() |
|
Log4jLogEvent(long timestamp)
Deprecated.
use
Log4jLogEvent.Builder instead. This constructor will be removed in an upcoming release. |
|
Log4jLogEvent(java.lang.String loggerName,
Marker marker,
java.lang.String loggerFQCN,
Level level,
Message message,
java.util.List<Property> properties,
java.lang.Throwable t)
Constructor.
|
|
Log4jLogEvent(java.lang.String loggerName,
Marker marker,
java.lang.String loggerFQCN,
Level level,
Message message,
java.lang.Throwable t)
Deprecated.
use
Log4jLogEvent.Builder instead. This constructor will be removed in an upcoming release. |
|
Log4jLogEvent(java.lang.String loggerName,
Marker marker,
java.lang.String loggerFQCN,
Level level,
Message message,
java.lang.Throwable t,
java.util.Map<java.lang.String,java.lang.String> mdc,
ThreadContext.ContextStack ndc,
java.lang.String threadName,
java.lang.StackTraceElement location,
long timestampMillis)
Deprecated.
use
Log4jLogEvent.Builder instead. This constructor will be removed in an upcoming release. |
private |
Log4jLogEvent(java.lang.String loggerName,
Marker marker,
java.lang.String loggerFQCN,
Level level,
Message message,
java.lang.Throwable thrown,
ThrowableProxy thrownProxy,
StringMap contextData,
ThreadContext.ContextStack contextStack,
long threadId,
java.lang.String threadName,
int threadPriority,
java.lang.StackTraceElement source,
long timestampMillis,
long nanoTime)
Constructor.
|
| Modifier and Type | Method and Description |
|---|---|
Log4jLogEvent.Builder |
asBuilder()
Returns a new fully initialized
Log4jLogEvent.Builder containing a copy of all fields of this event. |
static java.lang.StackTraceElement |
calcLocation(java.lang.String fqcnOfLogger) |
static boolean |
canDeserialize(java.io.Serializable event) |
private static StringMap |
createContextData(java.util.List<Property> properties) |
private static StringMap |
createContextData(java.util.Map<java.lang.String,java.lang.String> contextMap) |
static Log4jLogEvent |
createEvent(java.lang.String loggerName,
Marker marker,
java.lang.String loggerFQCN,
Level level,
Message message,
java.lang.Throwable thrown,
ThrowableProxy thrownProxy,
java.util.Map<java.lang.String,java.lang.String> mdc,
ThreadContext.ContextStack ndc,
java.lang.String threadName,
java.lang.StackTraceElement location,
long timestamp)
Deprecated.
use
Log4jLogEvent.Builder instead. This method will be removed in an upcoming release. |
LogEvent |
createMemento() |
static LogEvent |
createMemento(LogEvent logEvent) |
static Log4jLogEvent |
createMemento(LogEvent event,
boolean includeLocation)
Creates and returns a new immutable copy of this
Log4jLogEvent. |
static Log4jLogEvent |
deserialize(java.io.Serializable event) |
boolean |
equals(java.lang.Object o) |
ReadOnlyStringMap |
getContextData()
Returns the
ReadOnlyStringMap containing context data key-value pairs. |
java.util.Map<java.lang.String,java.lang.String> |
getContextMap()
Returns the immutable copy of the ThreadContext Map.
|
ThreadContext.ContextStack |
getContextStack()
Returns an immutable copy of the ThreadContext stack.
|
Level |
getLevel()
Returns the logging Level.
|
java.lang.String |
getLoggerFqcn()
The fully qualified class name of the class that was called by the caller.
|
java.lang.String |
getLoggerName()
Returns the name of the Logger used to generate the event.
|
Marker |
getMarker()
Returns the Marker associated with the event, or null.
|
Message |
getMessage()
Returns the Message associated with the event.
|
static NanoClock |
getNanoClock()
Returns the
NanoClock to use for creating the nanoTime timestamp of log events. |
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.
|
java.lang.StackTraceElement |
getSource()
Returns the StackTraceElement for the caller.
|
long |
getThreadId()
Gets the thread ID.
|
java.lang.String |
getThreadName()
Returns the name of the Thread on which the event was generated.
|
int |
getThreadPriority()
Gets the thread priority.
|
java.lang.Throwable |
getThrown()
Returns the Throwable associated with the event, or null.
|
ThrowableProxy |
getThrownProxy()
Returns the ThrowableProxy associated with the event, or null.
|
long |
getTimeMillis()
Returns the time in milliseconds from the epoch when the event occurred.
|
int |
hashCode() |
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 |
makeMessageImmutable() |
static Log4jLogEvent.Builder |
newBuilder()
Returns a new empty
Log4jLogEvent.Builder with all fields empty. |
private void |
readObject(java.io.ObjectInputStream stream) |
static java.io.Serializable |
serialize(Log4jLogEvent event,
boolean includeLocation)
Take a snapshot of the specified
Log4jLogEvent. |
static java.io.Serializable |
serialize(LogEvent event,
boolean includeLocation)
Take a snapshot of the specified
LogEvent. |
void |
setEndOfBatch(boolean endOfBatch)
Sets whether this event is the last one in a batch.
|
void |
setIncludeLocation(boolean includeLocation)
Sets whether the source of the logging request is required downstream.
|
static void |
setNanoClock(NanoClock nanoClock)
Sets the
NanoClock to use for creating the nanoTime timestamp of log events. |
Log4jLogEvent |
toImmutable()
Returns an immutable version of this log event, which MAY BE a copy of this event.
|
java.lang.String |
toString() |
protected java.lang.Object |
writeReplace()
Creates a LogEventProxy that can be serialized.
|
private static final long serialVersionUID
private static final Clock CLOCK
private static volatile NanoClock nanoClock
private static final ContextDataInjector CONTEXT_DATA_INJECTOR
private final java.lang.String loggerFqcn
private final Marker marker
private final Level level
private final java.lang.String loggerName
private Message message
private final long timeMillis
private final transient java.lang.Throwable thrown
private ThrowableProxy thrownProxy
private final StringMap contextData
private final ThreadContext.ContextStack contextStack
private long threadId
private java.lang.String threadName
private int threadPriority
private java.lang.StackTraceElement source
private boolean includeLocation
private boolean endOfBatch
private final transient long nanoTime
public Log4jLogEvent()
@Deprecated public Log4jLogEvent(long timestamp)
Log4jLogEvent.Builder instead. This constructor will be removed in an upcoming release.@Deprecated
public Log4jLogEvent(java.lang.String loggerName,
Marker marker,
java.lang.String loggerFQCN,
Level level,
Message message,
java.lang.Throwable t)
Log4jLogEvent.Builder instead. This constructor will be removed in an upcoming release.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.public Log4jLogEvent(java.lang.String loggerName,
Marker marker,
java.lang.String loggerFQCN,
Level level,
Message message,
java.util.List<Property> properties,
java.lang.Throwable t)
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.@Deprecated
public Log4jLogEvent(java.lang.String loggerName,
Marker marker,
java.lang.String loggerFQCN,
Level level,
Message message,
java.lang.Throwable t,
java.util.Map<java.lang.String,java.lang.String> mdc,
ThreadContext.ContextStack ndc,
java.lang.String threadName,
java.lang.StackTraceElement location,
long timestampMillis)
Log4jLogEvent.Builder instead. This constructor will be removed in an upcoming release.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.private Log4jLogEvent(java.lang.String loggerName,
Marker marker,
java.lang.String loggerFQCN,
Level level,
Message message,
java.lang.Throwable thrown,
ThrowableProxy thrownProxy,
StringMap contextData,
ThreadContext.ContextStack contextStack,
long threadId,
java.lang.String threadName,
int threadPriority,
java.lang.StackTraceElement source,
long timestampMillis,
long nanoTime)
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.nanoTime - The value of the running Java Virtual Machine's high-resolution time source when the event was
created.public static Log4jLogEvent.Builder newBuilder()
Log4jLogEvent.Builder with all fields empty.@Deprecated public static Log4jLogEvent createEvent(java.lang.String loggerName, Marker marker, java.lang.String loggerFQCN, Level level, Message message, java.lang.Throwable thrown, ThrowableProxy thrownProxy, java.util.Map<java.lang.String,java.lang.String> mdc, ThreadContext.ContextStack ndc, java.lang.String threadName, java.lang.StackTraceElement location, long timestamp)
Log4jLogEvent.Builder instead. This method will be removed in an upcoming release.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.private static StringMap createContextData(java.util.Map<java.lang.String,java.lang.String> contextMap)
public static NanoClock getNanoClock()
NanoClock to use for creating the nanoTime timestamp of log events.NanoClock to use for creating the nanoTime timestamp of log eventspublic static void setNanoClock(NanoClock nanoClock)
NanoClock to use for creating the nanoTime timestamp of log events.
FOR INTERNAL USE. This method may be called with a different NanoClock implementation when the
configuration changes.
nanoClock - the NanoClock to use for creating the nanoTime timestamp of log eventspublic Log4jLogEvent.Builder asBuilder()
Log4jLogEvent.Builder containing a copy of all fields of this event.public Log4jLogEvent toImmutable()
LogEventtoImmutable in interface LogEventpublic Level getLevel()
public java.lang.String getLoggerName()
getLoggerName in interface LogEventpublic Message getMessage()
getMessage in interface LogEventpublic void makeMessageImmutable()
public long getThreadId()
LogEventgetThreadId in interface LogEventpublic java.lang.String getThreadName()
getThreadName in interface LogEventpublic int getThreadPriority()
LogEventgetThreadPriority in interface LogEventpublic long getTimeMillis()
getTimeMillis in interface LogEventSystem.currentTimeMillis()public java.lang.Throwable getThrown()
public ThrowableProxy getThrownProxy()
getThrownProxy in interface LogEventpublic Marker getMarker()
public java.lang.String getLoggerFqcn()
getLoggerFqcn in interface LogEventpublic ReadOnlyStringMap getContextData()
ReadOnlyStringMap containing context data key-value pairs.getContextData in interface LogEventReadOnlyStringMap containing context data key-value pairsContextDataInjector,
ThreadContextpublic java.util.Map<java.lang.String,java.lang.String> getContextMap()
getContextMap in interface LogEventpublic ThreadContext.ContextStack getContextStack()
getContextStack in interface LogEventpublic java.lang.StackTraceElement getSource()
public static java.lang.StackTraceElement calcLocation(java.lang.String fqcnOfLogger)
public boolean isIncludeLocation()
LogEventStackTrace snapshot or not before handing off this event to
another thread.isIncludeLocation in interface LogEventtrue if the source of the logging request is required downstream, false otherwise.LogEvent.getSource()public void setIncludeLocation(boolean includeLocation)
LogEventStackTrace snapshot or not before handing off this event to
another thread.setIncludeLocation in interface LogEventincludeLocation - true if the source of the logging request is required downstream, false
otherwise.LogEvent.getSource()public boolean isEndOfBatch()
LogEventtrue 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.isEndOfBatch in interface LogEventpublic void setEndOfBatch(boolean endOfBatch)
LogEventimmediateFlush=true configuration.setEndOfBatch in interface LogEventendOfBatch - true if this event is the last one in a batch, false otherwise.public long getNanoTime()
LogEventgetNanoTime in interface LogEventprotected java.lang.Object writeReplace()
public static java.io.Serializable serialize(LogEvent event, boolean includeLocation)
LogEvent.event - the event to take a snapshot ofincludeLocation - if true, this method will obtain caller location informationSerializable objectdeserialize(Serializable),
serialize(Log4jLogEvent, boolean)public static java.io.Serializable serialize(Log4jLogEvent event, boolean includeLocation)
Log4jLogEvent.event - the event to take a snapshot ofincludeLocation - if true, this method will obtain caller location informationSerializable objectdeserialize(Serializable),
serialize(LogEvent, boolean)public static boolean canDeserialize(java.io.Serializable event)
public static Log4jLogEvent deserialize(java.io.Serializable event)
private void readObject(java.io.ObjectInputStream stream)
throws java.io.InvalidObjectException
java.io.InvalidObjectExceptionpublic LogEvent createMemento()
public static Log4jLogEvent createMemento(LogEvent event, boolean includeLocation)
Log4jLogEvent.Log4jLogEventpublic java.lang.String toString()
toString in class java.lang.Objectpublic boolean equals(java.lang.Object o)
equals in class java.lang.Objectpublic int hashCode()
hashCode in class java.lang.Object