Top Description Fields Constructors Methods
ch.qos.logback.classic.spi

public Class LoggingEvent

extends Object
implements ILoggingEvent
Class Inheritance
All Implemented Interfaces
ch.qos.logback.classic.spi.ILoggingEvent, ch.qos.logback.core.spi.DeferredProcessingAware
Imports
java.io.IOException, .ObjectOutputStream, java.lang.reflect.InvocationTargetException, .Method, java.time.Clock, .Instant, java.util.ArrayList, .Collections, .List, .Map, ch.qos.logback.core.CoreConstants, ch.qos.logback.core.util.EnvUtil, .StringUtil, org.slf4j.Marker, org.slf4j.event.KeyValuePair, org.slf4j.helpers.MessageFormatter, org.slf4j.spi.MDCAdapter, ch.qos.logback.classic.Level, .Logger, .LoggerContext, ch.qos.logback.classic.util.LogbackMDCAdapter, ch.qos.logback.core.spi.SequenceNumberGenerator

The internal representation of logging events. When an affirmative decision is made to log then a LoggingEvent instance is created. This instance is passed around to the different logback-classic components.

Writers of logback-classic components such as appenders should be aware of that some of the LoggingEvent fields are initialized lazily. Therefore, an appender wishing to output data to be later correctly read by a receiver, must initialize "lazy" fields prior to writing them out. See the prepareForDeferredProcessing() method for the exact list.

Authors
Ceki Gülcü, Sébastien Pennec

Field Summary

Modifier and TypeField and Description
private transient Object[]
private StackTraceElement[]
pack-priv transient String
pack-priv transient String
fqnOfLoggerClass

Fully qualified name of the calling Logger class.

private Instant
instant

The number of milliseconds elapsed from 1/1/1970 until logging event was created.

pack-priv List<KeyValuePair>
private transient Level
level

Level of logging event.

private LoggerContext
private LoggerContextVO
private String
private List<Marker>
private Map<String, String>
private String
private int
public static final String
private long
private String
threadName

The name of thread in which this logging event was generated.

private ThrowableProxy
private long
public static final String

Constructor Summary

AccessConstructor and Description
public
public
LoggingEvent(String fqcn, Logger logger, Level level, String message, Throwable throwable, Object[] argArray)

Method Summary

Modifier and TypeMethod and Description
public void
public void
addMarker(Marker marker)

private String
extractThreadName(Thread aThread)

Extracts the name of aThread by calling Thread#getName().

private Throwable
public Object[]
public StackTraceElement[]
getCallerData()

Implements ch.qos.logback.classic.spi.ILoggingEvent.getCallerData.

Get the caller information for this logging event.
public long
public String
public Instant
getInstant()

Overrides default ch.qos.logback.classic.spi.ILoggingEvent.getInstant.

Return the Instant corresponding to the creation of this event.
public List<KeyValuePair>
public Level
public LoggerContextVO
public String
public List<Marker>
getMarkerList()

Implements ch.qos.logback.classic.spi.ILoggingEvent.getMarkerList.

Since SLF4J 2.0.0, the slf4j logging API assumes the possibility of multiple Marker instances in a logging event.
public Map<String, String>
getMdc()

Implements ch.qos.logback.classic.spi.ILoggingEvent.getMdc.

Deprecated Replaced by [@link #getMDCPropertyMap}
Synonym for [@link #getMDCPropertyMap}.
public Map<String, String>
public String
public int
public long
getSequenceNumber()

Implements ch.qos.logback.classic.spi.ILoggingEvent.getSequenceNumber.

The sequence number associated with this event.
public String
public IThrowableProxy
getThrowableProxy()

Implements ch.qos.logback.classic.spi.ILoggingEvent.getThrowableProxy.

Returns the throwable information contained within this event.
public long
getTimeStamp()

Implements ch.qos.logback.classic.spi.ILoggingEvent.getTimeStamp.

Return the number of elapsed milliseconds since epoch in UTC.
pack-priv Long

Returns:

Return the threadId if the thread is a virtual thread, return null otherwise.
getVirtualThreadId
(Thread aThread)

Return the threadId if running under JDK 21+ and the thread is a virtual thread, return null otherwise.

public boolean
hasCallerData()

Implements ch.qos.logback.classic.spi.ILoggingEvent.hasCallerData.

If this event has caller data, then true is returned.
pack-priv void
public void
prepareForDeferredProcessing()

Implements ch.qos.logback.classic.spi.ILoggingEvent.prepareForDeferredProcessing.

This method should be called prior to serializing an event.
public void
public void
setCallerData(StackTraceElement[] callerDataArray)

public void
setInstant(Instant instant)

Set Instant corresponding to the creation of this event.

public void
public void
setLevel(Level level)

public void
public void
public void
setLoggerName(String loggerName)

public void
setMDCPropertyMap(Map<String, String> map)

Set the MDC map for this event.

public void
setMessage(String message)

public void
public void
setThreadName(String
The threadName to set.
threadName
)

public void
setThrowableProxy(ThrowableProxy tp)

Set this event's throwable information.

public void
setTimeStamp(long timeStamp)

Set the number of elapsed milliseconds since epoch in UTC.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
private void
writeObject(ObjectOutputStream out)

LoggerEventVO instances should be used for serialization.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

argumentArrayback to summary
private transient Object[] argumentArray
callerDataArrayback to summary
private StackTraceElement[] callerDataArray
formattedMessageback to summary
pack-priv transient String formattedMessage
fqnOfLoggerClassback to summary
pack-priv transient String fqnOfLoggerClass

Fully qualified name of the calling Logger class. This field does not survive serialization.

Note that the getCallerInformation() method relies on this fact.

instantback to summary
private Instant instant

The number of milliseconds elapsed from 1/1/1970 until logging event was created.

keyValuePairsback to summary
pack-priv List<KeyValuePair> keyValuePairs
Since
1.3.0
levelback to summary
private transient Level level

Level of logging event.

This field should not be accessed directly. You should use the getLevel method instead.

loggerContextback to summary
private LoggerContext loggerContext
loggerContextVOback to summary
private LoggerContextVO loggerContextVO
loggerNameback to summary
private String loggerName
markerListback to summary
private List<Marker> markerList
mdcPropertyMapback to summary
private Map<String, String> mdcPropertyMap
messageback to summary
private String message
nanosecondsback to summary
private int nanoseconds
REGULAR_UNNAMED_THREAD_PREFIXback to summary
public static final String REGULAR_UNNAMED_THREAD_PREFIX
sequenceNumberback to summary
private long sequenceNumber
threadNameback to summary
private String threadName

The name of thread in which this logging event was generated.

throwableProxyback to summary
private ThrowableProxy throwableProxy
timeStampback to summary
private long timeStamp
VIRTUAL_THREAD_NAME_PREFIXback to summary
public static final String VIRTUAL_THREAD_NAME_PREFIX

Constructor Detail

LoggingEventback to summary
public LoggingEvent()
LoggingEventback to summary
public LoggingEvent(String fqcn, Logger logger, Level level, String message, Throwable throwable, Object[] argArray)

Method Detail

addKeyValuePairback to summary
public void addKeyValuePair(KeyValuePair kvp)
addMarkerback to summary
public void addMarker(Marker marker)
extractThreadNameback to summary
private String extractThreadName(Thread aThread)

Extracts the name of aThread by calling Thread#getName(). If the value is null, then use the value returned by Thread#getId() prefixing with VIRTUAL_THREAD_NAME_PREFIX if thread is virtual or with REGULAR_UNNAMED_THREAD_PREFIX if regular.

Since
1.5.0
extractThrowableAnRearrangeArgumentsback to summary
private Throwable extractThrowableAnRearrangeArguments(Object[] argArray)
getArgumentArrayback to summary
public Object[] getArgumentArray()

Implements ch.qos.logback.classic.spi.ILoggingEvent.getArgumentArray.

getCallerDataback to summary
public StackTraceElement[] getCallerData()

Implements ch.qos.logback.classic.spi.ILoggingEvent.getCallerData.

Get the caller information for this logging event. If caller information is null at the time of its invocation, this method extracts location information. The collected information is cached for future use.

Note that after serialization it is impossible to correctly extract caller information.

Returns:StackTraceElement[]

Doc from ch.qos.logback.classic.spi.ILoggingEvent.getCallerData.

the caller data associated with this event.

getContextBirthTimeback to summary
public long getContextBirthTime()
getFormattedMessageback to summary
public String getFormattedMessage()

Implements ch.qos.logback.classic.spi.ILoggingEvent.getFormattedMessage.

getInstantback to summary
public Instant getInstant()

Overrides default ch.qos.logback.classic.spi.ILoggingEvent.getInstant.

Return the Instant corresponding to the creation of this event.

Returns:Instant

Doc from ch.qos.logback.classic.spi.ILoggingEvent.getInstant.

the Instant the event was created.

Since
1.3
See Also
getTimeStamp()
getKeyValuePairsback to summary
public List<KeyValuePair> getKeyValuePairs()

Implements ch.qos.logback.classic.spi.ILoggingEvent.getKeyValuePairs.

Doc from ch.qos.logback.classic.spi.ILoggingEvent.getKeyValuePairs.

A list of KeyValuePair objects. The returned list may be null.

Returns:List<KeyValuePair>

may be null

Annotations
@Override
getLevelback to summary
public Level getLevel()

Implements ch.qos.logback.classic.spi.ILoggingEvent.getLevel.

getLoggerContextVOback to summary
public LoggerContextVO getLoggerContextVO()

Implements ch.qos.logback.classic.spi.ILoggingEvent.getLoggerContextVO.

getLoggerNameback to summary
public String getLoggerName()

Implements ch.qos.logback.classic.spi.ILoggingEvent.getLoggerName.

getMarkerListback to summary
public List<Marker> getMarkerList()

Implements ch.qos.logback.classic.spi.ILoggingEvent.getMarkerList.

Doc from ch.qos.logback.classic.spi.ILoggingEvent.getMarkerList.

Since SLF4J 2.0.0, the slf4j logging API assumes the possibility of multiple Marker instances in a logging event. Consequently, ILoggingEvent needs to cater for this possibility.

Returns:List<Marker>

the marker list, may be null

getMdcback to summary
public Map<String, String> getMdc()

Implements ch.qos.logback.classic.spi.ILoggingEvent.getMdc.

Deprecated

Replaced by [@link #getMDCPropertyMap}

Synonym for [@link #getMDCPropertyMap}.

getMDCPropertyMapback to summary
public Map<String, String> getMDCPropertyMap()

Implements ch.qos.logback.classic.spi.ILoggingEvent.getMDCPropertyMap.

Doc from ch.qos.logback.classic.spi.ILoggingEvent.getMDCPropertyMap.

Returns the MDC map. The returned value can be an empty map but not null.

getMessageback to summary
public String getMessage()

Implements ch.qos.logback.classic.spi.ILoggingEvent.getMessage.

getNanosecondsback to summary
public int getNanoseconds()

Implements ch.qos.logback.classic.spi.ILoggingEvent.getNanoseconds.

Return the number of nanoseconds past the timestamp in seconds.

Returns:int

Doc from ch.qos.logback.classic.spi.ILoggingEvent.getNanoseconds.

the number of elapsed nanoseconds as found in getInstant()

Annotations
@Override
Since
1.3.0
getSequenceNumberback to summary
public long getSequenceNumber()

Implements ch.qos.logback.classic.spi.ILoggingEvent.getSequenceNumber.

Doc from ch.qos.logback.classic.spi.ILoggingEvent.getSequenceNumber.

The sequence number associated with this event.

Sequence numbers, if present, should be increasing monotonically.

Annotations
@Override
getThreadNameback to summary
public String getThreadName()

Implements ch.qos.logback.classic.spi.ILoggingEvent.getThreadName.

getThrowableProxyback to summary
public IThrowableProxy getThrowableProxy()

Implements ch.qos.logback.classic.spi.ILoggingEvent.getThrowableProxy.

Returns the throwable information contained within this event. May be null if there is no such information.

getTimeStampback to summary
public long getTimeStamp()

Implements ch.qos.logback.classic.spi.ILoggingEvent.getTimeStamp.

Return the number of elapsed milliseconds since epoch in UTC.

Returns:long

Doc from ch.qos.logback.classic.spi.ILoggingEvent.getTimeStamp.

the number of elapsed milliseconds since epoch

getVirtualThreadIdback to summary
pack-priv Long getVirtualThreadId(Thread aThread)

Return the threadId if running under JDK 21+ and the thread is a virtual thread, return null otherwise.

Returns:Long

Return the threadId if the thread is a virtual thread, return null otherwise.

hasCallerDataback to summary
public boolean hasCallerData()

Implements ch.qos.logback.classic.spi.ILoggingEvent.hasCallerData.

Doc from ch.qos.logback.classic.spi.ILoggingEvent.hasCallerData.

If this event has caller data, then true is returned. Otherwise the returned value is null.

Logback components wishing to use caller data if available without causing it to be computed can invoke this method before invoking getCallerData().

Returns:boolean

whether this event has caller data

initTmestampFieldsback to summary
pack-priv void initTmestampFields(Instant instant)
prepareForDeferredProcessingback to summary
public void prepareForDeferredProcessing()

Implements ch.qos.logback.classic.spi.ILoggingEvent.prepareForDeferredProcessing.

This method should be called prior to serializing an event. It should also be called when using asynchronous or deferred logging.

Note that due to performance concerns, this method does NOT extract caller data. It is the responsibility of the caller to extract caller information.

setArgumentArrayback to summary
public void setArgumentArray(Object[] argArray)
setCallerDataback to summary
public void setCallerData(StackTraceElement[] callerDataArray)
setInstantback to summary
public void setInstant(Instant instant)

Set Instant corresponding to the creation of this event. The value of getTimeStamp() will be overridden as well.

setKeyValuePairsback to summary
public void setKeyValuePairs(List<KeyValuePair> kvpList)
setLevelback to summary
public void setLevel(Level level)
setLoggerContextback to summary
public void setLoggerContext(LoggerContext lc)
setLoggerContextRemoteViewback to summary
public void setLoggerContextRemoteView(LoggerContextVO loggerContextVO)
setLoggerNameback to summary
public void setLoggerName(String loggerName)
setMDCPropertyMapback to summary
public void setMDCPropertyMap(Map<String, String> map)

Set the MDC map for this event.

Since
1.0.8
setMessageback to summary
public void setMessage(String message)
setSequenceNumberback to summary
public void setSequenceNumber(long sn)
setThreadNameback to summary
public void setThreadName(String threadName) throws IllegalStateException
Parameters
threadName:String

The threadName to set.

Exceptions
IllegalStateException:
If threadName has been already set.
setThrowableProxyback to summary
public void setThrowableProxy(ThrowableProxy tp)

Set this event's throwable information.

setTimeStampback to summary
public void setTimeStamp(long timeStamp)

Set the number of elapsed milliseconds since epoch in UTC. Setting the timestamp will override the value contained in getInstant. Nanoseconds value will be computed form the provided millisecond value.

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object.

Annotations
@Override
writeObjectback to summary
private void writeObject(ObjectOutputStream out) throws IOException

LoggerEventVO instances should be used for serialization. Use build method to create the LoggerEventVO instance.

Since
1.0.11