org.jcoderz.commons
Class LogEvent

java.lang.Object
  extended by java.lang.Throwable
      extended by org.jcoderz.commons.LogEvent
All Implemented Interfaces:
Serializable, Loggable
Direct Known Subclasses:
AuditLogEvent

public class LogEvent
extends Throwable
implements Loggable

This is the Base class for log events.

The base class of this LogEvent is Throwable but instances of this class are not expected to be thrown.

Most functionality is implemented and documented by the LoggableImpl which is used a member of objects of this class.

Author:
Andreas Mandel
See Also:
org.jcoderz.commons, Serialized Form

Constructor Summary
LogEvent(LogMessageInfo messageInfo)
          Constructor getting an log message info.
LogEvent(LogMessageInfo messageInfo, Throwable cause)
          Constructor getting an log message info and a root exception.
 
Method Summary
 void addParameter(String name, Serializable value)
          Add a new parameter to the Loggable.
 Throwable getCause()
          Returns the cause of this throwable or null if the cause is nonexistent or unknown.
 long getEventTime()
          Returns the point in time when the event occurred.
 String getInstanceId()
          Returns the instance identifier of the process that generated this Loggable.
 LogMessageInfo getLogMessageInfo()
          Returns the LogMessageInfo for this Loggable.
 String getMessage()
          Returns the (Detail) message of this loggable.
 String getNodeId()
          Returns the ip-address or the host name where the Loggable was created.
 List getParameter(String name)
          Returns a list of all parameters with the given name.
 Set getParameterNames()
          Returns a set of available parameters.
 String getSourceClass()
          Tries to find the source class name where this log event was fired.
 String getSourceMethod()
          Tries to find the source method where this log event was fired.
 long getThreadId()
          Returns the thread id of the thread that created this Loggable.
 String getThreadName()
          Returns the thread name as it was valid at the time of creation of this Loggable.
 String getTrackingNumber()
          Returns the (unique) tracking number of this Loggable instance.
 Throwable initCause(Throwable cause)
          
 void log()
          Logs this Loggable into the appropriate log sink.
 String toDetailedString()
          The toString method of Loggable must dump out all information stored within this loggable in a readable way.
 String toString()
          The toString method of Loggable dumps the String representation of the class name of the loggable and the contained message.
 
Methods inherited from class java.lang.Throwable
fillInStackTrace, getLocalizedMessage, getStackTrace, printStackTrace, printStackTrace, printStackTrace, setStackTrace
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

LogEvent

public LogEvent(LogMessageInfo messageInfo)
Constructor getting an log message info.

Parameters:
messageInfo - the log message info for this exception

LogEvent

public LogEvent(LogMessageInfo messageInfo,
                Throwable cause)
Constructor getting an log message info and a root exception.

Parameters:
messageInfo - the log message info for this exception
cause - the problem that caused this exception to be thrown
Method Detail

initCause

public Throwable initCause(Throwable cause)

Overrides:
initCause in class Throwable

addParameter

public final void addParameter(String name,
                               Serializable value)
Add a new parameter to the Loggable. All parameters are always added to the Loggable. There is no way of changing or removing a parameter. Once the Loggable was asked for one of it's values there should not be a new parameter. Nevertheless implementations of this interface MUST not throw an exception if this happens. Multiple parameters with the same name are stored within the Loggable. Values must be Serializable and have a useful to String representation. If the value is not serializable it might be sufficient to store the String representation of the value. The Loggable is not responsible to make a deep copy of the value. The calling code should take care for this. To solve this a possible solution would again be to use the String representation of the value.

Specified by:
addParameter in interface Loggable
Parameters:
name - the name of the parameter to be added.
value - the value for the parameter.

getInstanceId

public String getInstanceId()
Returns the instance identifier of the process that generated this Loggable. The instance id should be a descriptive name for the process running the application. For example, on Bea WLS, we could use the Server name. If no such information is available, the OS Process ID should be used. The field might get truncated on the presentation layer.

Specified by:
getInstanceId in interface Loggable
Returns:
the instance identifier of the process that generated this Loggable.

getMessage

public final String getMessage()
Returns the (Detail) message of this loggable. The message is created using the pattern of the associated LogMessageInfo and parameters. The field might get truncated on the presentation layer.

Specified by:
getMessage in interface Loggable
Overrides:
getMessage in class Throwable
Returns:
the (Detail) message of this loggable.

log

public final void log()
Logs this Loggable into the appropriate log sink.

Specified by:
log in interface Loggable

getCause

public Throwable getCause()
Returns the cause of this throwable or null if the cause is nonexistent or unknown. (The cause is the throwable that caused this throwable to get thrown.) The returned object might be a Loggable.

Specified by:
getCause in interface Loggable
Overrides:
getCause in class Throwable
Returns:
the cause of this throwable or null if the cause is nonexistent or unknown.

getEventTime

public long getEventTime()
Returns the point in time when the event occurred. More general this is the point in time when the Loggable object was created.

Specified by:
getEventTime in interface Loggable
Returns:
the point in time when the event occurred, measured in milliseconds, between the current time and midnight, January 1, 1970 UTC.

getLogMessageInfo

public LogMessageInfo getLogMessageInfo()
Returns the LogMessageInfo for this Loggable.

Specified by:
getLogMessageInfo in interface Loggable
Returns:
the LogMessageInfo for this Loggable.

getNodeId

public String getNodeId()
Returns the ip-address or the host name where the Loggable was created. The field might get truncated on the presentation layer.

Specified by:
getNodeId in interface Loggable
Returns:
the ip-address or the host name where the process is running on.

getParameter

public List getParameter(String name)
Returns a list of all parameters with the given name. Even if the objects in the list are mutable clients are expected not to modify them and to make deep copies as needed. The name must not start with an _ character. These are reserved for internal use.

Specified by:
getParameter in interface Loggable
Parameters:
name - The name of the parameter to be retrieved.
Returns:
a list of serializable objects representing the values of the parameters with the given name.

getParameterNames

public Set getParameterNames()
Returns a set of available parameters.

Specified by:
getParameterNames in interface Loggable
Returns:
a set of available parameters.

getThreadId

public long getThreadId()
Returns the thread id of the thread that created this Loggable.

Specified by:
getThreadId in interface Loggable
Returns:
the thread id of the thread that created this Loggable.

getTrackingNumber

public String getTrackingNumber()
Returns the (unique) tracking number of this Loggable instance.

Specified by:
getTrackingNumber in interface Loggable
Returns:
the (unique) tracking number of this Loggable instance.

getSourceClass

public String getSourceClass()
Tries to find the source class name where this log event was fired.

Specified by:
getSourceClass in interface Loggable
Returns:
the name of the class
See Also:
StackTraceElement.getClassName()

getSourceMethod

public String getSourceMethod()
Tries to find the source method where this log event was fired.

Specified by:
getSourceMethod in interface Loggable
Returns:
the name of the method including the line number if available
See Also:
StackTraceElement.getMethodName(), StackTraceElement.getLineNumber()

getThreadName

public String getThreadName()
Returns the thread name as it was valid at the time of creation of this Loggable.

Specified by:
getThreadName in interface Loggable
Returns:
the thread name as it was valid at the time of creation of this Loggable.
See Also:
Thread.getName()

toString

public String toString()
The toString method of Loggable dumps the String representation of the class name of the loggable and the contained message.

Specified by:
toString in interface Loggable
Overrides:
toString in class Throwable
Returns:
one line information about this Loggable.

toDetailedString

public String toDetailedString()
The toString method of Loggable must dump out all information stored within this loggable in a readable way. This includes the information of possible nested data.

Specified by:
toDetailedString in interface Loggable
Returns:
a exhaustive dump of the data stored within this Loggable.


Copyright 2007 The jCoderZ Project.