FileDocCategorySizeDatePackage
LogRecord.javaAPI DocApache log4j 1.2.1511445Sat Aug 25 00:09:38 BST 2007org.apache.log4j.lf5

LogRecord

public abstract class LogRecord extends Object implements Serializable
LogRecord. A LogRecord encapsulates the details of your desired log request.
author
Michael J. Sikorsky
author
Robert Shaw

Fields Summary
protected static long
_seqCount
protected LogLevel
_level
protected String
_message
protected long
_sequenceNumber
protected long
_millis
protected String
_category
protected String
_thread
protected String
_thrownStackTrace
protected Throwable
_thrown
protected String
_ndc
protected String
_location
Constructors Summary
public LogRecord()


  //--------------------------------------------------------------------------
  //   Private Variables:
  //--------------------------------------------------------------------------

  //--------------------------------------------------------------------------
  //   Constructors:
  //--------------------------------------------------------------------------

    
    super();

    _millis = System.currentTimeMillis();
    _category = "Debug";
    _message = "";
    _level = LogLevel.INFO;
    _sequenceNumber = getNextId();
    _thread = Thread.currentThread().toString();
    _ndc = "";
    _location = "";
  
Methods Summary
public java.lang.StringgetCategory()
Get the category asscociated with this LogRecord. For a more detailed description of what a category is see setCategory().

return
The category of this record.
see
#setCategory(String)

    return (_category);
  
public org.apache.log4j.lf5.LogLevelgetLevel()
Get the level of this LogRecord.

return
The LogLevel of this record.
see
#setLevel(LogLevel)
see
LogLevel

    return (_level);
  
public java.lang.StringgetLocation()
Get the location in code where this LogRecord originated.

return
The string containing the location information.

    return _location;
  
public java.lang.StringgetMessage()
Get the message asscociated with this LogRecord.

return
The message of this record.
see
#setMessage(String)

    return (_message);
  
public longgetMillis()
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();

return
The event time of this record in milliseconds from 1970.
see
#setMillis(long)

    return _millis;
  
public java.lang.StringgetNDC()
Get the NDC (nested diagnostic context) for this record.

return
The string representing the NDC.

    return _ndc;
  
protected static synchronized longgetNextId()

    _seqCount++;
    return _seqCount;
  
public longgetSequenceNumber()
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.

return
The sequence number of this record.
see
#setSequenceNumber(long)

    return (_sequenceNumber);
  
public java.lang.StringgetThreadDescription()
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.

return
The thread description of this record.
see
#setThreadDescription(String)

    return (_thread);
  
public java.lang.ThrowablegetThrown()
Get the Throwable associated with this LogRecord.

return
The LogLevel of this record.
see
#setThrown(Throwable)
see
#getThrownStackTrace()

    return (_thrown);
  
public java.lang.StringgetThrownStackTrace()
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.

return
The Stack Trace for the asscoiated Throwable of this LogRecord.
see
#setThrown(Throwable)
see
#getThrown()

    return (_thrownStackTrace);
  
public booleanhasThrown()

return
true if getThrown().toString() is a non-empty string.

    Throwable thrown = getThrown();
    if (thrown == null) {
      return false;
    }
    String thrownString = thrown.toString();
    return thrownString != null && thrownString.trim().length() != 0;
  
public booleanisFatal()

return
true if isSevereLevel() or hasThrown() returns true.

    return isSevereLevel() || hasThrown();
  
public abstract booleanisSevereLevel()
Abstract method. Must be overridden to indicate what log level to show in red.

public static synchronized voidresetSequenceNumber()
Resets that sequence number to 0.

    _seqCount = 0;
  
public voidsetCategory(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().

param
category The category for this record.
see
#getCategory()

    _category = category;
  
public voidsetLevel(org.apache.log4j.lf5.LogLevel level)
Set the level of this LogRecord.

param
level The LogLevel for this record.
see
#getLevel()
see
LogLevel

    _level = level;
  
public voidsetLocation(java.lang.String location)
Set the location in code where this LogRecord originated.

param
location A string containing location information.

    _location = location;
  
public voidsetMessage(java.lang.String message)
Set the message associated with this LogRecord.

param
message The message for this record.
see
#getMessage()

    _message = message;
  
public voidsetMillis(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.

param
millis The time in milliseconds from 1970.
see
#getMillis()

    _millis = millis;
  
public voidsetNDC(java.lang.String ndc)
Set the NDC (nested diagnostic context) for this record.

param
ndc A string representing the NDC.

    _ndc = ndc;
  
public voidsetSequenceNumber(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.

param
number The sequence number.
see
#getSequenceNumber()

    _sequenceNumber = number;
  
public voidsetThreadDescription(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.

param
threadDescription The description of the thread for this record.
see
#getThreadDescription()

    _thread = threadDescription;
  
public voidsetThrown(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.

param
thrown A Throwable to associate with this LogRecord.
see
#getThrown()
see
#getThrownStackTrace()

    if (thrown == null) {
      return;
    }
    _thrown = thrown;
    StringWriter sw = new StringWriter();
    PrintWriter out = new PrintWriter(sw);
    thrown.printStackTrace(out);
    out.flush();
    _thrownStackTrace = sw.toString();
    try {
      out.close();
      sw.close();
    } catch (IOException e) {
      // Do nothing, this should not happen as it is StringWriter.
    }
    out = null;
    sw = null;
  
public voidsetThrownStackTrace(java.lang.String trace)
Set the ThrownStackTrace for the log record.

param
trace A String to associate with this LogRecord
see
#getThrownStackTrace()

    _thrownStackTrace = trace;
  
public java.lang.StringtoString()
Return a String representation of this LogRecord.

    StringBuffer buf = new StringBuffer();
    buf.append("LogRecord: [" + _level + ", " + _message + "]");
    return (buf.toString());