- java.lang.Object
-
- ch.qos.logback.classic.spi.LoggingEvent
-
- All Implemented Interfaces:
ILoggingEvent,DeferredProcessingAware
public class LoggingEvent extends Object implements ILoggingEvent
The internal representation of logging events. When an affirmative decision is made to log then aLoggingEventinstance 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.- Author:
- Ceki Gülcü, Sébastien Pennec
-
-
Field Summary
Fields Modifier and Type Field Description static StringREGULAR_UNNAMED_THREAD_PREFIXstatic StringVIRTUAL_THREAD_NAME_PREFIX
-
Constructor Summary
Constructors Constructor Description LoggingEvent()LoggingEvent(String fqcn, Logger logger, Level level, String message, Throwable throwable, Object[] argArray)
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidaddKeyValuePair(org.slf4j.event.KeyValuePair kvp)voidaddMarker(org.slf4j.Marker marker)Object[]getArgumentArray()StackTraceElement[]getCallerData()Get the caller information for this logging event.longgetContextBirthTime()StringgetFormattedMessage()InstantgetInstant()Return theInstantcorresponding to the creation of this event.List<org.slf4j.event.KeyValuePair>getKeyValuePairs()A list ofKeyValuePairobjects.LevelgetLevel()LoggerContextVOgetLoggerContextVO()StringgetLoggerName()List<org.slf4j.Marker>getMarkerList()Since SLF4J 2.0.0, the slf4j logging API assumes the possibility of multiple Marker instances in a logging event.Map<String,String>getMdc()Deprecated.Replaced by [@link #getMDCPropertyMap}Map<String,String>getMDCPropertyMap()Returns the MDC map.StringgetMessage()intgetNanoseconds()Return the number of nanoseconds past thetimestamp in seconds.longgetSequenceNumber()The sequence number associated with this event.StringgetThreadName()IThrowableProxygetThrowableProxy()Returns the throwable information contained within this event.longgetTimeStamp()Return the number of elapsed milliseconds since epoch in UTC.booleanhasCallerData()If this event has caller data, then true is returned.voidprepareForDeferredProcessing()This method should be called prior to serializing an event.voidsetArgumentArray(Object[] argArray)voidsetCallerData(StackTraceElement[] callerDataArray)voidsetInstant(Instant instant)SetInstantcorresponding to the creation of this event.voidsetKeyValuePairs(List<org.slf4j.event.KeyValuePair> kvpList)voidsetLevel(Level level)voidsetLoggerContext(LoggerContext lc)voidsetLoggerContextRemoteView(LoggerContextVO loggerContextVO)voidsetLoggerName(String loggerName)voidsetMDCPropertyMap(Map<String,String> map)Set the MDC map for this event.voidsetMessage(String message)voidsetSequenceNumber(long sn)voidsetThreadName(String threadName)voidsetThrowableProxy(ThrowableProxy tp)Set this event's throwable information.voidsetTimeStamp(long timeStamp)Set the number of elapsed milliseconds since epoch in UTC.StringtoString()-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface ch.qos.logback.classic.spi.ILoggingEvent
getMarker
-
-
-
-
Field Detail
-
VIRTUAL_THREAD_NAME_PREFIX
public static final String VIRTUAL_THREAD_NAME_PREFIX
- See Also:
- Constant Field Values
-
REGULAR_UNNAMED_THREAD_PREFIX
public static final String REGULAR_UNNAMED_THREAD_PREFIX
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
LoggingEvent
public LoggingEvent()
-
-
Method Detail
-
setArgumentArray
public void setArgumentArray(Object[] argArray)
-
getArgumentArray
public Object[] getArgumentArray()
- Specified by:
getArgumentArrayin interfaceILoggingEvent
-
addKeyValuePair
public void addKeyValuePair(org.slf4j.event.KeyValuePair kvp)
-
setKeyValuePairs
public void setKeyValuePairs(List<org.slf4j.event.KeyValuePair> kvpList)
-
getKeyValuePairs
public List<org.slf4j.event.KeyValuePair> getKeyValuePairs()
Description copied from interface:ILoggingEventA list ofKeyValuePairobjects. The returned list may be null.- Specified by:
getKeyValuePairsin interfaceILoggingEvent- Returns:
- may be null
-
getLevel
public Level getLevel()
- Specified by:
getLevelin interfaceILoggingEvent
-
getLoggerName
public String getLoggerName()
- Specified by:
getLoggerNamein interfaceILoggingEvent
-
setLoggerName
public void setLoggerName(String loggerName)
-
getThreadName
public String getThreadName()
- Specified by:
getThreadNamein interfaceILoggingEvent
-
setThreadName
public void setThreadName(String threadName) throws IllegalStateException
- Parameters:
threadName- The threadName to set.- Throws:
IllegalStateException- If threadName has been already set.
-
getThrowableProxy
public IThrowableProxy getThrowableProxy()
Returns the throwable information contained within this event. May benullif there is no such information.- Specified by:
getThrowableProxyin interfaceILoggingEvent
-
setThrowableProxy
public void setThrowableProxy(ThrowableProxy tp)
Set this event's throwable information.
-
prepareForDeferredProcessing
public void 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.- Specified by:
prepareForDeferredProcessingin interfaceDeferredProcessingAware- Specified by:
prepareForDeferredProcessingin interfaceILoggingEvent
-
setLoggerContext
public void setLoggerContext(LoggerContext lc)
-
getLoggerContextVO
public LoggerContextVO getLoggerContextVO()
- Specified by:
getLoggerContextVOin interfaceILoggingEvent
-
setLoggerContextRemoteView
public void setLoggerContextRemoteView(LoggerContextVO loggerContextVO)
-
getMessage
public String getMessage()
- Specified by:
getMessagein interfaceILoggingEvent
-
setMessage
public void setMessage(String message)
-
getInstant
public Instant getInstant()
Return theInstantcorresponding to the creation of this event.- Specified by:
getInstantin interfaceILoggingEvent- Returns:
- the
Instantthe event was created. - Since:
- 1.3
-
setInstant
public void setInstant(Instant instant)
SetInstantcorresponding to the creation of this event. The value ofgetTimeStamp()will be overridden as well.
-
getTimeStamp
public long getTimeStamp()
Return the number of elapsed milliseconds since epoch in UTC.- Specified by:
getTimeStampin interfaceILoggingEvent- Returns:
- the number of elapsed milliseconds since epoch
-
getNanoseconds
public int getNanoseconds()
Return the number of nanoseconds past thetimestamp in seconds.- Specified by:
getNanosecondsin interfaceILoggingEvent- Returns:
- the number of elapsed nanoseconds as found in
ILoggingEvent.getInstant() - Since:
- 1.3.0
-
setTimeStamp
public void setTimeStamp(long timeStamp)
Set the number of elapsed milliseconds since epoch in UTC. Setting the timestamp will override the value contained ingetInstant(). Nanoseconds value will be computed form the provided millisecond value.
-
getSequenceNumber
public long getSequenceNumber()
Description copied from interface:ILoggingEventThe sequence number associated with this event.Sequence numbers, if present, should be increasing monotonically.
- Specified by:
getSequenceNumberin interfaceILoggingEvent
-
setSequenceNumber
public void setSequenceNumber(long sn)
-
getCallerData
public StackTraceElement[] 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.
- Specified by:
getCallerDatain interfaceILoggingEvent- Returns:
- the caller data associated with this event.
- See Also:
ILoggingEvent.hasCallerData()
-
hasCallerData
public boolean hasCallerData()
Description copied from interface:ILoggingEventIf 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
ILoggingEvent.getCallerData().- Specified by:
hasCallerDatain interfaceILoggingEvent- Returns:
- whether this event has caller data
-
setCallerData
public void setCallerData(StackTraceElement[] callerDataArray)
-
getMarkerList
public List<org.slf4j.Marker> getMarkerList()
Description copied from interface:ILoggingEventSince 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.- Specified by:
getMarkerListin interfaceILoggingEvent- Returns:
- the marker list, may be null
-
addMarker
public void addMarker(org.slf4j.Marker marker)
-
getContextBirthTime
public long getContextBirthTime()
-
getFormattedMessage
public String getFormattedMessage()
- Specified by:
getFormattedMessagein interfaceILoggingEvent
-
getMDCPropertyMap
public Map<String,String> getMDCPropertyMap()
Description copied from interface:ILoggingEventReturns the MDC map. The returned value can be an empty map but not null.- Specified by:
getMDCPropertyMapin interfaceILoggingEvent
-
setMDCPropertyMap
public void setMDCPropertyMap(Map<String,String> map)
Set the MDC map for this event.- Parameters:
map-- Since:
- 1.0.8
-
getMdc
public Map<String,String> getMdc()
Deprecated.Replaced by [@link #getMDCPropertyMap}Synonym for [@link #getMDCPropertyMap}.- Specified by:
getMdcin interfaceILoggingEvent
-
-