public class Log4jLogEvent extends Object implements LogEvent
Modifier and Type | Class and Description |
---|---|
static class |
Log4jLogEvent.Builder
LogEvent Builder helper class.
|
Constructor and Description |
---|
Log4jLogEvent() |
Log4jLogEvent(long timestamp)
Deprecated.
use
Log4jLogEvent.Builder instead. This constructor will be removed in an upcoming release. |
Log4jLogEvent(String loggerName,
Marker marker,
String loggerFQCN,
Level level,
Message message,
List<Property> properties,
Throwable t)
Constructor.
|
Log4jLogEvent(String loggerName,
Marker marker,
String loggerFQCN,
Level level,
Message message,
Throwable t)
Deprecated.
use
Log4jLogEvent.Builder instead. This constructor will be removed in an upcoming release. |
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.
use
Log4jLogEvent.Builder instead. This constructor will be removed in an upcoming release. |
Log4jLogEvent(String loggerName,
Marker marker,
String loggerFQCN,
StackTraceElement source,
Level level,
Message message,
List<Property> properties,
Throwable t)
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 boolean |
canDeserialize(Serializable event) |
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.
use
Log4jLogEvent.Builder instead. This method will be removed in an upcoming release. |
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(Serializable event) |
boolean |
equals(Object o) |
ReadOnlyStringMap |
getContextData()
Returns the
ReadOnlyStringMap containing context data key-value pairs. |
Map<String,String> |
getContextMap()
Returns the immutable copy of the ThreadContext Map.
|
ThreadContext.ContextStack |
getContextStack()
Returns an immutable copy of the ThreadContext stack.
|
Instant |
getInstant()
Returns the Instant when the message was logged.
|
Level |
getLevel()
Returns the logging Level.
|
String |
getLoggerFqcn()
The fully qualified class name of the class that was called by the caller.
|
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.
|
StackTraceElement |
getSource()
Returns the StackTraceElement for the caller.
|
long |
getThreadId()
Gets the thread ID.
|
String |
getThreadName()
Returns the name of the Thread on which the event was generated.
|
int |
getThreadPriority()
Gets the thread priority.
|
Throwable |
getThrown()
Returns the Throwable associated with the event, or null.
|
ThrowableProxy |
getThrownProxy()
Returns the ThrowableProxy associated with the event, or null.
|
long |
getTimeMillis()
Gets event time in milliseconds since midnight, January 1, 1970 UTC.
|
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. |
static Serializable |
serialize(Log4jLogEvent event,
boolean includeLocation)
Take a snapshot of the specified
Log4jLogEvent . |
static 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.
|
String |
toString() |
protected Object |
writeReplace()
Creates a LogEventProxy that can be serialized.
|
public Log4jLogEvent()
@Deprecated public Log4jLogEvent(long timestamp)
Log4jLogEvent.Builder
instead. This constructor will be removed in an upcoming release.@Deprecated public Log4jLogEvent(String loggerName, Marker marker, String loggerFQCN, Level level, Message message, 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(String loggerName, Marker marker, String loggerFQCN, Level level, Message message, List<Property> properties, 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.public Log4jLogEvent(String loggerName, Marker marker, String loggerFQCN, StackTraceElement source, Level level, Message message, List<Property> properties, 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(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)
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.public static Log4jLogEvent.Builder newBuilder()
Log4jLogEvent.Builder
with all fields empty.@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)
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.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()
LogEvent
toImmutable
in interface LogEvent
public Level getLevel()
public String getLoggerName()
getLoggerName
in interface LogEvent
public Message getMessage()
getMessage
in interface LogEvent
public void makeMessageImmutable()
public long getThreadId()
LogEvent
getThreadId
in interface LogEvent
public String getThreadName()
getThreadName
in interface LogEvent
public int getThreadPriority()
LogEvent
getThreadPriority
in interface LogEvent
public long getTimeMillis()
LogEvent.getInstant()
to get higher precision timestamp information if available on this platform.getTimeMillis
in interface LogEvent
System.currentTimeMillis()
public 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.
getInstant
in interface LogEvent
Instant
holding Instant details for this log eventpublic Throwable getThrown()
public ThrowableProxy getThrownProxy()
getThrownProxy
in interface LogEvent
public Marker getMarker()
public String getLoggerFqcn()
getLoggerFqcn
in interface LogEvent
public ReadOnlyStringMap getContextData()
ReadOnlyStringMap
containing context data key-value pairs.getContextData
in interface LogEvent
ReadOnlyStringMap
containing context data key-value pairsContextDataInjector
,
ThreadContext
public Map<String,String> getContextMap()
getContextMap
in interface LogEvent
public ThreadContext.ContextStack getContextStack()
getContextStack
in interface LogEvent
public StackTraceElement getSource()
public boolean isIncludeLocation()
LogEvent
StackTrace
snapshot or not before handing off this event to
another thread.isIncludeLocation
in interface LogEvent
true
if the source of the logging request is required downstream, false
otherwise.LogEvent.getSource()
public void setIncludeLocation(boolean includeLocation)
LogEvent
StackTrace
snapshot or not before handing off this event to
another thread.setIncludeLocation
in interface LogEvent
includeLocation
- true
if the source of the logging request is required downstream, false
otherwise.LogEvent.getSource()
public boolean isEndOfBatch()
LogEvent
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.isEndOfBatch
in interface LogEvent
public void setEndOfBatch(boolean endOfBatch)
LogEvent
immediateFlush=true
configuration.setEndOfBatch
in interface LogEvent
endOfBatch
- true
if this event is the last one in a batch, false
otherwise.public long getNanoTime()
LogEvent
getNanoTime
in interface LogEvent
protected Object writeReplace()
public static 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 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(Serializable event)
public static Log4jLogEvent deserialize(Serializable event)
public static Log4jLogEvent createMemento(LogEvent event, boolean includeLocation)
Log4jLogEvent
.Log4jLogEvent
Copyright © 1999-2023 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.