Package org.apache.log4j.lf5
Class LogRecord
- java.lang.Object
-
- org.apache.log4j.lf5.LogRecord
-
- All Implemented Interfaces:
java.io.Serializable
- Direct Known Subclasses:
Log4JLogRecord
public abstract class LogRecord extends java.lang.Object implements java.io.Serializable
LogRecord. A LogRecord encapsulates the details of your desired log request.- Author:
- Michael J. Sikorsky, Robert Shaw
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected java.lang.String
_category
protected LogLevel
_level
protected java.lang.String
_location
protected java.lang.String
_message
protected long
_millis
protected java.lang.String
_ndc
protected static long
_seqCount
protected long
_sequenceNumber
protected java.lang.String
_thread
protected java.lang.Throwable
_thrown
protected java.lang.String
_thrownStackTrace
-
Constructor Summary
Constructors Constructor Description LogRecord()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description java.lang.String
getCategory()
Get the category asscociated with this LogRecord.LogLevel
getLevel()
Get the level of this LogRecord.java.lang.String
getLocation()
Get the location in code where this LogRecord originated.java.lang.String
getMessage()
Get the message asscociated with this LogRecord.long
getMillis()
Get the event time of this record in milliseconds from 1970.java.lang.String
getNDC()
Get the NDC (nested diagnostic context) for this record.protected static long
getNextId()
long
getSequenceNumber()
Get the sequence number associated with this LogRecord.java.lang.String
getThreadDescription()
Get the thread description asscociated with this LogRecord.java.lang.Throwable
getThrown()
Get the Throwable associated with this LogRecord.java.lang.String
getThrownStackTrace()
Get the stack trace in a String-based format for the associated Throwable of this LogRecord.boolean
hasThrown()
boolean
isFatal()
abstract boolean
isSevereLevel()
Abstract method.static void
resetSequenceNumber()
Resets that sequence number to 0.void
setCategory(java.lang.String category)
Set the category associated with this LogRecord.void
setLevel(LogLevel level)
Set the level of this LogRecord.void
setLocation(java.lang.String location)
Set the location in code where this LogRecord originated.void
setMessage(java.lang.String message)
Set the message associated with this LogRecord.void
setMillis(long millis)
Set the event time of this record.void
setNDC(java.lang.String ndc)
Set the NDC (nested diagnostic context) for this record.void
setSequenceNumber(long number)
Set the sequence number assocsiated with this LogRecord.void
setThreadDescription(java.lang.String threadDescription)
Set the thread description associated with this LogRecord.void
setThrown(java.lang.Throwable thrown)
Set the Throwable associated with this LogRecord.void
setThrownStackTrace(java.lang.String trace)
Set the ThrownStackTrace for the log record.java.lang.String
toString()
Return a String representation of this LogRecord.
-
-
-
Field Detail
-
_seqCount
protected static long _seqCount
-
_level
protected LogLevel _level
-
_message
protected java.lang.String _message
-
_sequenceNumber
protected long _sequenceNumber
-
_millis
protected long _millis
-
_category
protected java.lang.String _category
-
_thread
protected java.lang.String _thread
-
_thrownStackTrace
protected java.lang.String _thrownStackTrace
-
_thrown
protected java.lang.Throwable _thrown
-
_ndc
protected java.lang.String _ndc
-
_location
protected java.lang.String _location
-
-
Method Detail
-
getLevel
public LogLevel getLevel()
Get the level of this LogRecord.- Returns:
- The LogLevel of this record.
- See Also:
setLevel(LogLevel)
,LogLevel
-
setLevel
public void setLevel(LogLevel level)
Set the level of this LogRecord.- Parameters:
level
- The LogLevel for this record.- See Also:
getLevel()
,LogLevel
-
isSevereLevel
public abstract boolean isSevereLevel()
Abstract method. Must be overridden to indicate what log level to show in red.
-
hasThrown
public boolean hasThrown()
- Returns:
- true if getThrown().toString() is a non-empty string.
-
isFatal
public boolean isFatal()
- Returns:
- true if isSevereLevel() or hasThrown() returns true.
-
getCategory
public java.lang.String getCategory()
Get the category asscociated with this LogRecord. For a more detailed description of what a category is see setCategory().- Returns:
- The category of this record.
- See Also:
setCategory(String)
-
setCategory
public void setCategory(java.lang.String category)
Set the category associated with this LogRecord. A category represents a hierarchical dot (".") separated namespace for messages. The definition of a category is application specific, but a common convention is as follows:When logging messages for a particluar class you can use its class name: com.thoughtworks.framework.servlet.ServletServiceBroker.
Futhermore, to log a message for a particular method in a class add the method name: com.thoughtworks.framework.servlet.ServletServiceBroker.init().- Parameters:
category
- The category for this record.- See Also:
getCategory()
-
getMessage
public java.lang.String getMessage()
Get the message asscociated with this LogRecord.- Returns:
- The message of this record.
- See Also:
setMessage(String)
-
setMessage
public void setMessage(java.lang.String message)
Set the message associated with this LogRecord.- Parameters:
message
- The message for this record.- See Also:
getMessage()
-
getSequenceNumber
public long getSequenceNumber()
Get the sequence number associated with this LogRecord. Sequence numbers are generally assigned when a LogRecord is constructed. Sequence numbers start at 0 and increase with each newly constructed LogRocord.- Returns:
- The sequence number of this record.
- See Also:
setSequenceNumber(long)
-
setSequenceNumber
public void setSequenceNumber(long number)
Set the sequence number assocsiated with this LogRecord. A sequence number will automatically be assigned to evey newly constructed LogRecord, however, this method can override the value.- Parameters:
number
- The sequence number.- See Also:
getSequenceNumber()
-
getMillis
public long getMillis()
Get the event time of this record in milliseconds from 1970. When a LogRecord is constructed the event time is set but may be overridden by calling setMillis();- Returns:
- The event time of this record in milliseconds from 1970.
- See Also:
setMillis(long)
-
setMillis
public void setMillis(long millis)
Set the event time of this record. When a LogRecord is constructed the event time is set but may be overridden by calling this method.- Parameters:
millis
- The time in milliseconds from 1970.- See Also:
getMillis()
-
getThreadDescription
public java.lang.String getThreadDescription()
Get the thread description asscociated with this LogRecord. When a LogRecord is constructed, the thread description is set by calling: Thread.currentThread().toString(). You may supply a thread description of your own by calling the setThreadDescription(String) method.- Returns:
- The thread description of this record.
- See Also:
setThreadDescription(String)
-
setThreadDescription
public void setThreadDescription(java.lang.String threadDescription)
Set the thread description associated with this LogRecord. When a LogRecord is constructed, the thread description is set by calling: Thread.currentThread().toString(). You may supply a thread description of your own by calling this method.- Parameters:
threadDescription
- The description of the thread for this record.- See Also:
getThreadDescription()
-
getThrownStackTrace
public java.lang.String getThrownStackTrace()
Get the stack trace in a String-based format for the associated Throwable of this LogRecord. The stack trace in a String-based format is set when the setThrown(Throwable) method is called.Why do we need this method considering that we have the getThrown() and setThrown() methods? A Throwable object may not be serializable, however, a String representation of it is. Users of LogRecords should generally call this method over getThrown() for the reasons of serialization.
- Returns:
- The Stack Trace for the asscoiated Throwable of this LogRecord.
- See Also:
setThrown(Throwable)
,getThrown()
-
setThrownStackTrace
public void setThrownStackTrace(java.lang.String trace)
Set the ThrownStackTrace for the log record.- Parameters:
trace
- A String to associate with this LogRecord- See Also:
getThrownStackTrace()
-
getThrown
public java.lang.Throwable getThrown()
Get the Throwable associated with this LogRecord.- Returns:
- The LogLevel of this record.
- See Also:
setThrown(Throwable)
,getThrownStackTrace()
-
setThrown
public void setThrown(java.lang.Throwable thrown)
Set the Throwable associated with this LogRecord. When this method is called, the stack trace in a String-based format is made available via the getThrownStackTrace() method.- Parameters:
thrown
- A Throwable to associate with this LogRecord.- See Also:
getThrown()
,getThrownStackTrace()
-
toString
public java.lang.String toString()
Return a String representation of this LogRecord.- Overrides:
toString
in classjava.lang.Object
-
getNDC
public java.lang.String getNDC()
Get the NDC (nested diagnostic context) for this record.- Returns:
- The string representing the NDC.
-
setNDC
public void setNDC(java.lang.String ndc)
Set the NDC (nested diagnostic context) for this record.- Parameters:
ndc
- A string representing the NDC.
-
getLocation
public java.lang.String getLocation()
Get the location in code where this LogRecord originated.- Returns:
- The string containing the location information.
-
setLocation
public void setLocation(java.lang.String location)
Set the location in code where this LogRecord originated.- Parameters:
location
- A string containing location information.
-
resetSequenceNumber
public static void resetSequenceNumber()
Resets that sequence number to 0.
-
getNextId
protected static long getNextId()
-
-