Class LoggingEvent
- java.lang.Object
-
- org.apache.log4j.spi.LoggingEvent
-
- All Implemented Interfaces:
java.io.Serializable
public class LoggingEvent extends java.lang.Object implements java.io.Serializable
The internal representation of logging events. When an affirmative decision is made to log then aLoggingEvent
instance is created. This instance is passed around to the different log4j components.This class is of concern to those wishing to extend log4j.
- Since:
- 0.8.2
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description java.lang.String
categoryName
Deprecated.This field will be marked as private in future releases.java.lang.String
fqnOfCategoryClass
Fully qualified name of the calling category class.Priority
level
Deprecated.This field will be marked as private in future releases.private LocationInfo
locationInfo
Location information for the caller.private Category
logger
Deprecated.This field will be marked as private or be completely removed in future releases.private java.util.Hashtable
mdcCopy
The mapped diagnostic context (MDC) of logging event.private boolean
mdcCopyLookupRequired
Have we tried to do an MDC lookup? If we did, there is no need to do it again.private java.lang.Object
message
The application supplied message of logging event.(package private) static java.util.Hashtable
methodCache
private java.lang.String
ndc
The nested diagnostic context (NDC) of logging event.private boolean
ndcLookupRequired
Have we tried to do an NDC lookup? If we did, there is no need to do it again.(package private) static java.lang.Integer[]
PARAM_ARRAY
private java.lang.String
renderedMessage
The application supplied message rendered through the log4j objet rendering mechanism.(package private) static long
serialVersionUID
private static long
startTime
private java.lang.String
threadName
The name of thread in which this logging event was generated.private ThrowableInformation
throwableInfo
This variable contains information about this event's throwablelong
timeStamp
The number of milliseconds elapsed from 1/1/1970 until logging event was created.(package private) static java.lang.String
TO_LEVEL
(package private) static java.lang.Class[]
TO_LEVEL_PARAMS
-
Constructor Summary
Constructors Constructor Description LoggingEvent(java.lang.String fqnOfCategoryClass, Category logger, long timeStamp, Level level, java.lang.Object message, java.lang.String threadName, ThrowableInformation throwable, java.lang.String ndc, LocationInfo info, java.util.Map properties)
Create new instance.LoggingEvent(java.lang.String fqnOfCategoryClass, Category logger, long timeStamp, Priority level, java.lang.Object message, java.lang.Throwable throwable)
Instantiate a LoggingEvent from the supplied parameters.LoggingEvent(java.lang.String fqnOfCategoryClass, Category logger, Priority level, java.lang.Object message, java.lang.Throwable throwable)
Instantiate a LoggingEvent from the supplied parameters.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.String
getFQNOfLoggerClass()
Get the fully qualified name of the calling logger sub-class/wrapper.Level
getLevel()
Return the level of this event.LocationInfo
getLocationInformation()
Set the location information for this logging event.Category
getLogger()
Gets the logger of the event.java.lang.String
getLoggerName()
Return the name of the logger.java.lang.Object
getMDC(java.lang.String key)
Returns the the context corresponding to thekey
parameter.void
getMDCCopy()
Obtain a copy of this thread's MDC prior to serialization or asynchronous logging.java.lang.Object
getMessage()
Return the message for this logging event.java.lang.String
getNDC()
This method returns the NDC for this event.java.util.Map
getProperties()
Returns the set of properties for the event.java.lang.String
getProperty(java.lang.String key)
Return a property for this event.java.util.Set
getPropertyKeySet()
Returns the set of the key values in the properties for the event.java.lang.String
getRenderedMessage()
static long
getStartTime()
Returns the time when the application started, in milliseconds elapsed since 01.01.1970.java.lang.String
getThreadName()
ThrowableInformation
getThrowableInformation()
Returns the throwable information contained within this event.java.lang.String[]
getThrowableStrRep()
Return this event's throwable's string[] representaion.long
getTimeStamp()
Getter for the event's time stamp.boolean
locationInformationExists()
Check for the existence of location information without creating it (a byproduct of calling getLocationInformation).private void
readLevel(java.io.ObjectInputStream ois)
private void
readObject(java.io.ObjectInputStream ois)
java.lang.Object
removeProperty(java.lang.String propName)
This removes the specified MDC property from the event.void
setProperty(java.lang.String propName, java.lang.String propValue)
Set value for MDC property.private void
writeLevel(java.io.ObjectOutputStream oos)
private void
writeObject(java.io.ObjectOutputStream oos)
-
-
-
Field Detail
-
startTime
private static long startTime
-
fqnOfCategoryClass
public final transient java.lang.String fqnOfCategoryClass
Fully qualified name of the calling category class.
-
logger
private transient Category logger
Deprecated.This field will be marked as private or be completely removed in future releases. Please do not use it.The category of the logging event. This field is not serialized for performance reasons.It is set by the LoggingEvent constructor or set by a remote entity after deserialization.
-
categoryName
public final java.lang.String categoryName
Deprecated.This field will be marked as private in future releases. Please do not access it directly. Use thegetLoggerName()
method instead.The category (logger) name.
-
level
public transient Priority level
Deprecated.This field will be marked as private in future releases. Please do not access it directly. Use thegetLevel()
method instead.Level of logging event. Level cannot be serializable because it is a flyweight. Due to its special seralization it cannot be declared final either.This field should not be accessed directly. You shoud use the
getLevel()
method instead.
-
ndc
private java.lang.String ndc
The nested diagnostic context (NDC) of logging event.
-
mdcCopy
private java.util.Hashtable mdcCopy
The mapped diagnostic context (MDC) of logging event.
-
ndcLookupRequired
private boolean ndcLookupRequired
Have we tried to do an NDC lookup? If we did, there is no need to do it again. Note that its value is always false when serialized. Thus, a receiving SocketNode will never use it's own (incorrect) NDC. See also writeObject method.
-
mdcCopyLookupRequired
private boolean mdcCopyLookupRequired
Have we tried to do an MDC lookup? If we did, there is no need to do it again. Note that its value is always false when serialized. See also the getMDC and getMDCCopy methods.
-
message
private transient java.lang.Object message
The application supplied message of logging event.
-
renderedMessage
private java.lang.String renderedMessage
The application supplied message rendered through the log4j objet rendering mechanism.
-
threadName
private java.lang.String threadName
The name of thread in which this logging event was generated.
-
throwableInfo
private ThrowableInformation throwableInfo
This variable contains information about this event's throwable
-
timeStamp
public final long timeStamp
The number of milliseconds elapsed from 1/1/1970 until logging event was created.
-
locationInfo
private LocationInfo locationInfo
Location information for the caller.
-
serialVersionUID
static final long serialVersionUID
- See Also:
- Constant Field Values
-
PARAM_ARRAY
static final java.lang.Integer[] PARAM_ARRAY
-
TO_LEVEL
static final java.lang.String TO_LEVEL
- See Also:
- Constant Field Values
-
TO_LEVEL_PARAMS
static final java.lang.Class[] TO_LEVEL_PARAMS
-
methodCache
static final java.util.Hashtable methodCache
-
-
Constructor Detail
-
LoggingEvent
public LoggingEvent(java.lang.String fqnOfCategoryClass, Category logger, Priority level, java.lang.Object message, java.lang.Throwable throwable)
Instantiate a LoggingEvent from the supplied parameters.Except
timeStamp
all the other fields ofLoggingEvent
are filled when actually needed.- Parameters:
logger
- The logger generating this event.level
- The level of this event.message
- The message of this event.throwable
- The throwable of this event.
-
LoggingEvent
public LoggingEvent(java.lang.String fqnOfCategoryClass, Category logger, long timeStamp, Priority level, java.lang.Object message, java.lang.Throwable throwable)
Instantiate a LoggingEvent from the supplied parameters.Except
timeStamp
all the other fields ofLoggingEvent
are filled when actually needed.- Parameters:
logger
- The logger generating this event.timeStamp
- the timestamp of this logging eventlevel
- The level of this event.message
- The message of this event.throwable
- The throwable of this event.
-
LoggingEvent
public LoggingEvent(java.lang.String fqnOfCategoryClass, Category logger, long timeStamp, Level level, java.lang.Object message, java.lang.String threadName, ThrowableInformation throwable, java.lang.String ndc, LocationInfo info, java.util.Map properties)
Create new instance.- Parameters:
fqnOfCategoryClass
- Fully qualified class name of Logger implementation.logger
- The logger generating this event.timeStamp
- the timestamp of this logging eventlevel
- The level of this event.message
- The message of this event.threadName
- thread namethrowable
- The throwable of this event.ndc
- Nested diagnostic contextinfo
- Location infoproperties
- MDC properties- Since:
- 1.2.15
-
-
Method Detail
-
getLocationInformation
public LocationInfo getLocationInformation()
Set the location information for this logging event. The collected information is cached for future use.
-
getLevel
public Level getLevel()
Return the level of this event. Use this form instead of directly accessing thelevel
field.
-
getLoggerName
public java.lang.String getLoggerName()
Return the name of the logger. Use this form instead of directly accessing thecategoryName
field.
-
getLogger
public Category getLogger()
Gets the logger of the event. Use should be restricted to cloning events.- Since:
- 1.2.15
-
getMessage
public java.lang.Object getMessage()
Return the message for this logging event.Before serialization, the returned object is the message passed by the user to generate the logging event. After serialization, the returned value equals the String form of the message possibly after object rendering.
- Since:
- 1.1
-
getNDC
public java.lang.String getNDC()
This method returns the NDC for this event. It will return the correct content even if the event was generated in a different thread or even on a different machine. TheNDC.get()
method should never be called directly.
-
getMDC
public java.lang.Object getMDC(java.lang.String key)
Returns the the context corresponding to thekey
parameter. If there is a local MDC copy, possibly because we are in a logging server or running inside AsyncAppender, then we search for the key in MDC copy, if a value is found it is returned. Otherwise, if the search in MDC copy returns a null result, then the current thread'sMDC
is used.Note that both the local MDC copy and the current thread's MDC are searched.
-
getMDCCopy
public void getMDCCopy()
Obtain a copy of this thread's MDC prior to serialization or asynchronous logging.
-
getRenderedMessage
public java.lang.String getRenderedMessage()
-
getStartTime
public static long getStartTime()
Returns the time when the application started, in milliseconds elapsed since 01.01.1970.
-
getThreadName
public java.lang.String getThreadName()
-
getThrowableInformation
public ThrowableInformation getThrowableInformation()
Returns the throwable information contained within this event. May benull
if there is no such information.Note that the
Throwable
object contained within aThrowableInformation
does not survive serialization.- Since:
- 1.1
-
getThrowableStrRep
public java.lang.String[] getThrowableStrRep()
Return this event's throwable's string[] representaion.
-
readLevel
private void readLevel(java.io.ObjectInputStream ois) throws java.io.IOException, java.lang.ClassNotFoundException
- Throws:
java.io.IOException
java.lang.ClassNotFoundException
-
readObject
private void readObject(java.io.ObjectInputStream ois) throws java.io.IOException, java.lang.ClassNotFoundException
- Throws:
java.io.IOException
java.lang.ClassNotFoundException
-
writeObject
private void writeObject(java.io.ObjectOutputStream oos) throws java.io.IOException
- Throws:
java.io.IOException
-
writeLevel
private void writeLevel(java.io.ObjectOutputStream oos) throws java.io.IOException
- Throws:
java.io.IOException
-
setProperty
public final void setProperty(java.lang.String propName, java.lang.String propValue)
Set value for MDC property. This adds the specified MDC property to the event. Access to the MDC is not synchronized, so this method should only be called when it is known that no other threads are accessing the MDC.- Parameters:
propName
-propValue
-- Since:
- 1.2.15
-
getProperty
public final java.lang.String getProperty(java.lang.String key)
Return a property for this event. The return value can be null. Equivalent to getMDC(String) in log4j 1.2. Provided for compatibility with log4j 1.3.- Parameters:
key
- property name- Returns:
- property value or null if property not set
- Since:
- 1.2.15
-
locationInformationExists
public final boolean locationInformationExists()
Check for the existence of location information without creating it (a byproduct of calling getLocationInformation).- Returns:
- true if location information has been extracted.
- Since:
- 1.2.15
-
getTimeStamp
public final long getTimeStamp()
Getter for the event's time stamp. The time stamp is calculated starting from 1970-01-01 GMT.- Returns:
- timestamp
- Since:
- 1.2.15
-
getPropertyKeySet
public java.util.Set getPropertyKeySet()
Returns the set of the key values in the properties for the event. The returned set is unmodifiable by the caller. Provided for compatibility with log4j 1.3- Returns:
- Set an unmodifiable set of the property keys.
- Since:
- 1.2.15
-
getProperties
public java.util.Map getProperties()
Returns the set of properties for the event. The returned set is unmodifiable by the caller. Provided for compatibility with log4j 1.3- Returns:
- Set an unmodifiable map of the properties.
- Since:
- 1.2.15
-
getFQNOfLoggerClass
public java.lang.String getFQNOfLoggerClass()
Get the fully qualified name of the calling logger sub-class/wrapper. Provided for compatibility with log4j 1.3- Returns:
- fully qualified class name, may be null.
- Since:
- 1.2.15
-
removeProperty
public java.lang.Object removeProperty(java.lang.String propName)
This removes the specified MDC property from the event. Access to the MDC is not synchronized, so this method should only be called when it is known that no other threads are accessing the MDC.- Parameters:
propName
- the property name to remove- Since:
- 1.2.16
-
-