org.jcoderz.commons
Class LoggableImpl

java.lang.Object
  extended by org.jcoderz.commons.LoggableImpl
All Implemented Interfaces:
Serializable, Loggable

public class LoggableImpl
extends Object
implements Serializable, Loggable

Implements code common to all Exceptions.

The two base exceptions BaseException and BaseRuntimeException and the LogEvent use a object of this class as a member and delegate all common calls to this member.

This class also implements the special Loggable that allows to add named parameters and to get a more detailed logging, with an assigned error message.

The error response id is used to mark log entries with an unique id. This id is also returned to the client (caller). If the client reports the error response id it can be used to find a specific log entries more quickly. If the nested exception has already an error response id, it is re-used for this exception and will not get a new one.

Functionality provided by this class is:

Author:
Andreas Mandel
See Also:
Serialized Form

Field Summary
static String APPLICATION_NAME_PARAMETER_NAME
          Name of the application of the loggable.
static String CAUSE_PARAMETER_NAME
          Key used for the root cause added to the loggable.
static String CLASSNAME
          Name of this class.
static String CONTEXT_PARAMETER_PREFIX
          Context parameter values prefix.
static String EVENT_TIME_PARAMETER_NAME
          Key used for the event time parameter of the loggable.
static String GROUP_NAME_PARAMETER_NAME
          Name of the group of the loggable.
static String INSTANCE_ID
          Id for this instance.
static String INSTANCE_ID_PARAMETER_NAME
          Key used for the instance id parameter object.
static Logger logger
          Logger used for this class.
static String MESSAGE_INFO_PARAMETER_NAME
          Key used for the log message info parameter object.
static String NODE_ID
          This nodes id.
static String NODE_ID_PARAMETER_NAME
          Key used for the node id parameter object.
static org.jcoderz.commons.LoggableImpl.ThreadIdHolder THREAD_ID_GENERATOR
          Virtual thread Id generated for this thread.
static String THREAD_ID_PARAMETER_NAME
          Key used for the thread id parameter object.
static String THREAD_NAME_PARAMETER_NAME
          Key used for the thread name parameter object.
static String TRACKING_NUMBER_PARAMETER_NAME
          Key used for the error response id added to the loggable.
 
Constructor Summary
LoggableImpl(Loggable outer, LogMessageInfo errorId)
          Create this loggable provide the 'Loggable' functionality for the given outer loggable.
LoggableImpl(Loggable outer, LogMessageInfo errorId, long threadId, String threadName, String instanceId, String nodeId)
          Create this loggable provide the 'Loggable' functionality for the given outer loggable with the given dynamic parameters.
LoggableImpl(Loggable outer, LogMessageInfo errorId, long threadId, String threadName, String instanceId, String nodeId, Throwable cause)
          Create this loggable provide the 'Loggable' functionality for the given outer loggable with the given dynamic parameters and an initial cause..
LoggableImpl(Loggable outer, LogMessageInfo errorId, Throwable cause)
          Create this loggable provide the 'Loggable' functionality for the given outer loggable with an initial cause.
 
Method Summary
 void addParameter(String name, Serializable value)
          Adds a new named parameter.
 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.
 void initCause(Throwable cause)
          Sets the cause of this throwable.
 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.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

CLASSNAME

public static final String CLASSNAME
Name of this class.


logger

public static final Logger logger
Logger used for this class.


MESSAGE_INFO_PARAMETER_NAME

public static final String MESSAGE_INFO_PARAMETER_NAME
Key used for the log message info parameter object.

See Also:
Constant Field Values

TRACKING_NUMBER_PARAMETER_NAME

public static final String TRACKING_NUMBER_PARAMETER_NAME
Key used for the error response id added to the loggable.

See Also:
Constant Field Values

CAUSE_PARAMETER_NAME

public static final String CAUSE_PARAMETER_NAME
Key used for the root cause added to the loggable.

See Also:
Constant Field Values

THREAD_ID_PARAMETER_NAME

public static final String THREAD_ID_PARAMETER_NAME
Key used for the thread id parameter object.

See Also:
Constant Field Values

THREAD_NAME_PARAMETER_NAME

public static final String THREAD_NAME_PARAMETER_NAME
Key used for the thread name parameter object.

See Also:
Constant Field Values

INSTANCE_ID_PARAMETER_NAME

public static final String INSTANCE_ID_PARAMETER_NAME
Key used for the instance id parameter object.

See Also:
Constant Field Values

NODE_ID_PARAMETER_NAME

public static final String NODE_ID_PARAMETER_NAME
Key used for the node id parameter object.

See Also:
Constant Field Values

EVENT_TIME_PARAMETER_NAME

public static final String EVENT_TIME_PARAMETER_NAME
Key used for the event time parameter of the loggable.

See Also:
Constant Field Values

APPLICATION_NAME_PARAMETER_NAME

public static final String APPLICATION_NAME_PARAMETER_NAME
Name of the application of the loggable.

See Also:
Constant Field Values

GROUP_NAME_PARAMETER_NAME

public static final String GROUP_NAME_PARAMETER_NAME
Name of the group of the loggable.

See Also:
Constant Field Values

CONTEXT_PARAMETER_PREFIX

public static final String CONTEXT_PARAMETER_PREFIX
Context parameter values prefix.

See Also:
Constant Field Values

NODE_ID

public static final String NODE_ID
This nodes id.


INSTANCE_ID

public static final String INSTANCE_ID
Id for this instance.


THREAD_ID_GENERATOR

public static final org.jcoderz.commons.LoggableImpl.ThreadIdHolder THREAD_ID_GENERATOR
Virtual thread Id generated for this thread.

Constructor Detail

LoggableImpl

public LoggableImpl(Loggable outer,
                    LogMessageInfo errorId)
Create this loggable provide the 'Loggable' functionality for the given outer loggable.

Parameters:
outer - the the outer loggable.
errorId - the static LogMessageInfo for this Loggable.

LoggableImpl

public LoggableImpl(Loggable outer,
                    LogMessageInfo errorId,
                    Throwable cause)
Create this loggable provide the 'Loggable' functionality for the given outer loggable with an initial cause.

Parameters:
outer - the the outer loggable.
errorId - the static LogMessageInfo for this Loggable.
cause - the cause of the outer.

LoggableImpl

public LoggableImpl(Loggable outer,
                    LogMessageInfo errorId,
                    long threadId,
                    String threadName,
                    String instanceId,
                    String nodeId)
Create this loggable provide the 'Loggable' functionality for the given outer loggable with the given dynamic parameters.

Parameters:
outer - the the outer loggable.
errorId - the static LogMessageInfo for this Loggable.
threadId - the threadId to be set.
threadName - the threadName to be set.
instanceId - the instanceId to be set.
nodeId - the nodeId to be set.

LoggableImpl

public LoggableImpl(Loggable outer,
                    LogMessageInfo errorId,
                    long threadId,
                    String threadName,
                    String instanceId,
                    String nodeId,
                    Throwable cause)
Create this loggable provide the 'Loggable' functionality for the given outer loggable with the given dynamic parameters and an initial cause..

Parameters:
outer - the the outer loggable.
errorId - the static LogMessageInfo for this Loggable.
threadId - the threadId to be set.
threadName - the threadName to be set.
instanceId - the instanceId to be set.
nodeId - the nodeId to be set.
cause - the cause of the outer.
Method Detail

initCause

public final void initCause(Throwable cause)
Sets the cause of this throwable. This method should be called after the call to the Throwable.initCause(Throwable) for the case the super call fails.

Parameters:
cause - the cause of this Exception.

addParameter

public final void addParameter(String name,
                               Serializable value)
Adds a new named parameter. The parameter is added at the end of the list of parameters. The same name might occur several times.

Specified by:
addParameter in interface Loggable
Parameters:
name - the name of the parameter.
value - The value of the parameter

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.

getLogMessageInfo

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

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

getTrackingNumber

public final 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.

getEventTime

public final 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.

getNodeId

public final 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.

getInstanceId

public final 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.

getThreadId

public final 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.

getThreadName

public final 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()

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
Returns:
the cause of this throwable or null if the cause is nonexistent or unknown.

log

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

Specified by:
log in interface Loggable

getMessage

public 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
Returns:
the (Detail) message of this loggable.

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()

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 Object
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.