org.perf4j.commonslog
Class CommonsLogStopWatch

java.lang.Object
  extended by org.perf4j.StopWatch
      extended by org.perf4j.LoggingStopWatch
          extended by org.perf4j.commonslog.CommonsLogStopWatch
All Implemented Interfaces:
Serializable, Cloneable

public class CommonsLogStopWatch
extends LoggingStopWatch

This LoggingStopWatch uses an Apache Commons Logging Log instance to persist the StopWatch messages.

Author:
Alex Devine
See Also:
Serialized Form

Field Summary
static int DEBUG_LEVEL
          Specifying this level will cause the debug() method to be used for logging.
static int ERROR_LEVEL
          Specifying this level will cause the error() method to be used for logging.
static int FATAL_LEVEL
          Specifying this level will cause the fatal() method to be used for logging.
static int INFO_LEVEL
          Specifying this level will cause the info() method to be used for logging.
static int TRACE_LEVEL
          Specifying this level will cause the trace() method to be used for logging.
static int WARN_LEVEL
          Specifying this level will cause the warn() method to be used for logging.
 
Fields inherited from class org.perf4j.StopWatch
DEFAULT_LOGGER_NAME
 
Constructor Summary
CommonsLogStopWatch()
          Creates a CommonsLogStopWatch with a blank tag, no message and started at the instant of creation.
CommonsLogStopWatch(Log logger)
          Creates a CommonsLogStopWatch with a blank tag, no message and started at the instant of creation, using the specified Log to log stop watch messages using the info() method, or using the warn() method if an exception is passed to one of the stop or lap methods.
CommonsLogStopWatch(Log logger, int normalPriority)
          Creates a CommonsLogStopWatch with a blank tag, no message and started at the instant of creation, using the specified Log to log stop watch messages at the normalPriority level specified, or using the warn() method if an exception is passed to one of the stop or lap methods.
CommonsLogStopWatch(Log logger, int normalPriority, int exceptionPriority)
          Creates a CommonsLogStopWatch with a blank tag, no message and started at the instant of creation, using the specified Log to log stop watch messages at the normalPriority level specified, or at the exceptionPriority level if an exception is passed to one of the stop or lap methods.
CommonsLogStopWatch(long startTime, long elapsedTime, String tag, String message, Log logger, int normalPriority, int exceptionPriority)
          This constructor is mainly used for creation of StopWatch instances from logs and for testing.
CommonsLogStopWatch(String tag)
          Creates a CommonsLogStopWatch with the tag specified, no message and started at the instant of creation.
CommonsLogStopWatch(String tag, Log logger)
          Creates a CommonsLogStopWatch with the tag specified, no message and started at the instant of creation, using the specified Log to log stop watch using the info() method, or using the warn() method if an exception is passed to one of the stop or lap methods.
CommonsLogStopWatch(String tag, Log logger, int normalPriority)
          Creates a CommonsLogStopWatch with the tag specified, no message and started at the instant of creation, using the specified Log to log stop watch messages at the normalPriority level specified, or using the warn() level if an exception is passed to one of the stop or lap methods.
CommonsLogStopWatch(String tag, Log logger, int normalPriority, int exceptionPriority)
          Creates a CommonsLogStopWatch with the tag specified, no message and started at the instant of creation, using the specified Log to log stop watch messages at the normalPriority level specified, or at the exceptionPriority level if an exception is passed to one of the stop or lap methods.
CommonsLogStopWatch(String tag, String message)
          Creates a CommonsLogStopWatch with the tag and message specified and started at the instant of creation.
CommonsLogStopWatch(String tag, String message, Log logger)
          Creates a CommonsLogStopWatch with the tag and message specified and started at the instant of creation, using the specified Log to log stop watch messages using the info() method, or using the warn() method if an exception is passed to one of the stop or lap methods.
CommonsLogStopWatch(String tag, String message, Log logger, int normalPriority)
          Creates a CommonsLogStopWatch with the tag and message specified and started at the instant of creation, using the specified Log to log stop watch messages at the normalPriority level specified, or using the warn() method if an exception is passed to one of the stop or lap methods.
CommonsLogStopWatch(String tag, String message, Log logger, int normalPriority, int exceptionPriority)
          Creates a CommonsLogStopWatch with the tag and message specified and started at the instant of creation, using the specified Log to log stop watch messages at the normalPriority level specified, or at the exceptionPriority level if an exception is passed to one of the stop or lap methods.
 
Method Summary
 CommonsLogStopWatch clone()
           
 int getExceptionPriority()
          Gets the level at which log statements will be made when one of the stop or lap methods that DOES take an exception is called.
 Log getLogger()
          Gets the Apache Commons Logging Log that is used to persist logging statements when one of the stop or lap methods is called.
 int getNormalPriority()
          Gets the level at which log statements will be made when one of the stop or lap methods that does NOT take an exception is called.
 boolean isLogging()
          This method returns true if the Log it uses is enabled at the normalPriority level of this StopWatch.
protected  boolean isLogging(int atLevel)
          Since Commons Logging doesn't have a first class notion of Level objects or integer values, this method converts the level value to one of the isXYZEnabled() methods on the Log.
protected  void log(String stopWatchAsString, Throwable exception)
          The log message is overridden to use the Apache Commons Logging Log to persist the stop watch.
protected  void log(String stopWatchAsString, Throwable exception, int atLevel)
          Since Commons Logging doesn't have a first class notion of Level objects or integer values, this method maps the atLevel parameter to one of the trace(), debug(), info(), warn(), error(), or fatal() methods on the Log.
static int mapLevelName(String levelName)
          This utility method provides the standard mapping between log4j level names (which Perf4J uses as the standard set of possible levels) to the corresponding ..._LEVEL constant from this class.
 void setExceptionPriority(int exceptionPriority)
          Sets the level at which log statements will be made when one of the stop or lap methods that DOES take an exception is called.
 void setLogger(Log logger)
          Sets the Apache Commons Logging Logused to persist StopWatch instances.
 void setNormalPriority(int normalPriority)
          Sets the level at which log statements will be made when one of the stop or lap methods that does NOT take an exception is called.
 
Methods inherited from class org.perf4j.LoggingStopWatch
lap, lap, stop, stop, stop, stop
 
Methods inherited from class org.perf4j.StopWatch
equals, getElapsedTime, getMessage, getStartTime, getTag, hashCode, lap, lap, setMessage, setTag, start, start, start, stop, stop, toString
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

TRACE_LEVEL

public static final int TRACE_LEVEL
Specifying this level will cause the trace() method to be used for logging.

See Also:
Constant Field Values

DEBUG_LEVEL

public static final int DEBUG_LEVEL
Specifying this level will cause the debug() method to be used for logging.

See Also:
Constant Field Values

INFO_LEVEL

public static final int INFO_LEVEL
Specifying this level will cause the info() method to be used for logging.

See Also:
Constant Field Values

WARN_LEVEL

public static final int WARN_LEVEL
Specifying this level will cause the warn() method to be used for logging.

See Also:
Constant Field Values

ERROR_LEVEL

public static final int ERROR_LEVEL
Specifying this level will cause the error() method to be used for logging.

See Also:
Constant Field Values

FATAL_LEVEL

public static final int FATAL_LEVEL
Specifying this level will cause the fatal() method to be used for logging.

See Also:
Constant Field Values
Constructor Detail

CommonsLogStopWatch

public CommonsLogStopWatch()
Creates a CommonsLogStopWatch with a blank tag, no message and started at the instant of creation. The Log with the name "org.perf4j.TimingLogger" is used to log stop watch messages using the info() method, or using the warn() method if an exception is passed to one of the stop or lap methods.


CommonsLogStopWatch

public CommonsLogStopWatch(Log logger)
Creates a CommonsLogStopWatch with a blank tag, no message and started at the instant of creation, using the specified Log to log stop watch messages using the info() method, or using the warn() method if an exception is passed to one of the stop or lap methods.

Parameters:
logger - The Log to use when persisting StopWatches in one of the stop or lap methods.

CommonsLogStopWatch

public CommonsLogStopWatch(Log logger,
                           int normalPriority)
Creates a CommonsLogStopWatch with a blank tag, no message and started at the instant of creation, using the specified Log to log stop watch messages at the normalPriority level specified, or using the warn() method if an exception is passed to one of the stop or lap methods.

Parameters:
logger - The Log to use when persisting StopWatches in one of the stop or lap methods.
normalPriority - The level at which this StopWatch is logged if one of the stop or lap methods that does NOT take an exception is called. Should be one of the ..._LEVEL constants from this class.

CommonsLogStopWatch

public CommonsLogStopWatch(Log logger,
                           int normalPriority,
                           int exceptionPriority)
Creates a CommonsLogStopWatch with a blank tag, no message and started at the instant of creation, using the specified Log to log stop watch messages at the normalPriority level specified, or at the exceptionPriority level if an exception is passed to one of the stop or lap methods.

Parameters:
logger - The Log to use when persisting StopWatches in one of the stop or lap methods.
normalPriority - The level at which this StopWatch is logged if one of the stop or lap methods that does NOT take an exception is called. Should be one of the ..._LEVEL constants from this class.
exceptionPriority - The level at which this StopWatch is logged if one of the stop or lap methods that DOES take an exception is called. Should be one of the ..._LEVEL constants from this class.

CommonsLogStopWatch

public CommonsLogStopWatch(String tag)
Creates a CommonsLogStopWatch with the tag specified, no message and started at the instant of creation. The Log with the name "org.perf4j.TimingLogger" is used to log stop watch messages using the info() method, or using the warn() method if an exception is passed to one of the stop or lap methods.

Parameters:
tag - The tag name for this timing call. Tags are used to group timing logs, thus each block of code being timed should have a unique tag. Note that tags can take a hierarchical format using dot notation.

CommonsLogStopWatch

public CommonsLogStopWatch(String tag,
                           Log logger)
Creates a CommonsLogStopWatch with the tag specified, no message and started at the instant of creation, using the specified Log to log stop watch using the info() method, or using the warn() method if an exception is passed to one of the stop or lap methods.

Parameters:
tag - The tag name for this timing call. Tags are used to group timing logs, thus each block of code being timed should have a unique tag. Note that tags can take a hierarchical format using dot notation.
logger - The Log to use when persisting StopWatches in one of the stop or lap methods.

CommonsLogStopWatch

public CommonsLogStopWatch(String tag,
                           Log logger,
                           int normalPriority)
Creates a CommonsLogStopWatch with the tag specified, no message and started at the instant of creation, using the specified Log to log stop watch messages at the normalPriority level specified, or using the warn() level if an exception is passed to one of the stop or lap methods.

Parameters:
tag - The tag name for this timing call. Tags are used to group timing logs, thus each block of code being timed should have a unique tag. Note that tags can take a hierarchical format using dot notation.
logger - The Log to use when persisting StopWatches in one of the stop or lap methods.
normalPriority - The level at which this StopWatch is logged if one of the stop or lap methods that does NOT take an exception is called. Should be one of the ..._LEVEL constants from this class.

CommonsLogStopWatch

public CommonsLogStopWatch(String tag,
                           Log logger,
                           int normalPriority,
                           int exceptionPriority)
Creates a CommonsLogStopWatch with the tag specified, no message and started at the instant of creation, using the specified Log to log stop watch messages at the normalPriority level specified, or at the exceptionPriority level if an exception is passed to one of the stop or lap methods.

Parameters:
tag - The tag name for this timing call. Tags are used to group timing logs, thus each block of code being timed should have a unique tag. Note that tags can take a hierarchical format using dot notation.
logger - The Log to use when persisting StopWatches in one of the stop or lap methods.
normalPriority - The level at which this StopWatch is logged if one of the stop or lap methods that does NOT take an exception is called. Should be one of the ..._LEVEL constants from this class.
exceptionPriority - The level at which this StopWatch is logged if one of the stop or lap methods that DOES take an exception is called. Should be one of the ..._LEVEL constants from this class.

CommonsLogStopWatch

public CommonsLogStopWatch(String tag,
                           String message)
Creates a CommonsLogStopWatch with the tag and message specified and started at the instant of creation. The Log with the name "org.perf4j.TimingLogger" is used to log stop watch messages using the info() method, or using the warn() method if an exception is passed to one of the stop or lap methods.

Parameters:
tag - The tag name for this timing call. Tags are used to group timing logs, thus each block of code being timed should have a unique tag. Note that tags can take a hierarchical format using dot notation.
message - Additional text to be printed with the logging statement of this StopWatch.

CommonsLogStopWatch

public CommonsLogStopWatch(String tag,
                           String message,
                           Log logger)
Creates a CommonsLogStopWatch with the tag and message specified and started at the instant of creation, using the specified Log to log stop watch messages using the info() method, or using the warn() method if an exception is passed to one of the stop or lap methods.

Parameters:
tag - The tag name for this timing call. Tags are used to group timing logs, thus each block of code being timed should have a unique tag. Note that tags can take a hierarchical format using dot notation.
message - Additional text to be printed with the logging statement of this StopWatch.
logger - The Log to use when persisting StopWatches in one of the stop or lap methods.

CommonsLogStopWatch

public CommonsLogStopWatch(String tag,
                           String message,
                           Log logger,
                           int normalPriority)
Creates a CommonsLogStopWatch with the tag and message specified and started at the instant of creation, using the specified Log to log stop watch messages at the normalPriority level specified, or using the warn() method if an exception is passed to one of the stop or lap methods.

Parameters:
tag - The tag name for this timing call. Tags are used to group timing logs, thus each block of code being timed should have a unique tag. Note that tags can take a hierarchical format using dot notation.
message - Additional text to be printed with the logging statement of this StopWatch.
logger - The Log to use when persisting StopWatches in one of the stop or lap methods.
normalPriority - The level at which this StopWatch is logged if one of the stop or lap methods that does NOT take an exception is called. Should be one of the ..._LEVEL constants from this class.

CommonsLogStopWatch

public CommonsLogStopWatch(String tag,
                           String message,
                           Log logger,
                           int normalPriority,
                           int exceptionPriority)
Creates a CommonsLogStopWatch with the tag and message specified and started at the instant of creation, using the specified Log to log stop watch messages at the normalPriority level specified, or at the exceptionPriority level if an exception is passed to one of the stop or lap methods.

Parameters:
tag - The tag name for this timing call. Tags are used to group timing logs, thus each block of code being timed should have a unique tag. Note that tags can take a hierarchical format using dot notation.
message - Additional text to be printed with the logging statement of this StopWatch.
logger - The Log to use when persisting StopWatches in one of the stop or lap methods.
normalPriority - The level at which this StopWatch is logged if one of the stop or lap methods that does NOT take an exception is called. Should be one of the ..._LEVEL constants from this class.
exceptionPriority - The level at which this StopWatch is logged if one of the stop or lap methods that DOES take an exception is called. Should be one of the ..._LEVEL constants from this class.

CommonsLogStopWatch

public CommonsLogStopWatch(long startTime,
                           long elapsedTime,
                           String tag,
                           String message,
                           Log logger,
                           int normalPriority,
                           int exceptionPriority)
This constructor is mainly used for creation of StopWatch instances from logs and for testing. Users should normally not call this constructor in client code.

Parameters:
startTime - The start time in milliseconds
elapsedTime - The elapsed time in milliseconds
tag - The tag used to group timing logs of the same code block
message - Additional message text
logger - The Log to use when persisting StopWatches in one of the stop or lap methods.
normalPriority - The level at which this StopWatch is logged if one of the stop or lap methods that does NOT take an exception is called.
exceptionPriority - The level at which this StopWatch is logged if one of the stop or lap methods that DOES take an exception is called.
Method Detail

getLogger

public Log getLogger()
Gets the Apache Commons Logging Log that is used to persist logging statements when one of the stop or lap methods is called.

Returns:
The Log used for StopWatch persistence.

setLogger

public void setLogger(Log logger)
Sets the Apache Commons Logging Logused to persist StopWatch instances.

Parameters:
logger - The Log this instance should use for persistence. May not be null.

getNormalPriority

public int getNormalPriority()
Gets the level at which log statements will be made when one of the stop or lap methods that does NOT take an exception is called. The value returned corresponds to one of the ..._LEVEL constants of this class.

Returns:
The level used when logging "normal" stop or lap calls.

setNormalPriority

public void setNormalPriority(int normalPriority)
Sets the level at which log statements will be made when one of the stop or lap methods that does NOT take an exception is called.

Parameters:
normalPriority - The level used when logging "normal" stop or lap calls. This value should be one of the ..._LEVEL constants of this class.

getExceptionPriority

public int getExceptionPriority()
Gets the level at which log statements will be made when one of the stop or lap methods that DOES take an exception is called. The value returned corresponds to one of the ..._LEVEL constants of this class.

Returns:
The level used when logging "exceptional" stop or lap calls.

setExceptionPriority

public void setExceptionPriority(int exceptionPriority)
Sets the level at which log statements will be made when one of the stop or lap methods that DOES take an exception is called.

Parameters:
exceptionPriority - The level used when logging "exceptional" stop or lap calls. This value should be one of the ..._LEVEL constants of this class.

isLogging

public boolean isLogging()
This method returns true if the Log it uses is enabled at the normalPriority level of this StopWatch.

Overrides:
isLogging in class LoggingStopWatch
Returns:
true if this StopWatch will output log messages when one of the stop or lap messages that does NOT take an exception is called.

log

protected void log(String stopWatchAsString,
                   Throwable exception)
The log message is overridden to use the Apache Commons Logging Log to persist the stop watch.

Overrides:
log in class LoggingStopWatch
Parameters:
stopWatchAsString - The stringified view of the stop watch for logging.
exception - An exception, if any, that was passed to the stop or lap method. If this is null then logging will occur at normalPriority, if non-null it will occur at exceptionPriority.

isLogging

protected boolean isLogging(int atLevel)
Since Commons Logging doesn't have a first class notion of Level objects or integer values, this method converts the level value to one of the isXYZEnabled() methods on the Log.

Parameters:
atLevel - The level at which a log message is logged.
Returns:
true if the Log used by this StopWatch will output messages at the level specified.

log

protected void log(String stopWatchAsString,
                   Throwable exception,
                   int atLevel)
Since Commons Logging doesn't have a first class notion of Level objects or integer values, this method maps the atLevel parameter to one of the trace(), debug(), info(), warn(), error(), or fatal() methods on the Log.

Parameters:
stopWatchAsString - The stringified view of the stop watch for logging.
exception - An exception, if any, that was passed to the stop or lap method. If this is null then logging will occur at normalPriority, if non-null it will occur at exceptionPriority.
atLevel - The level at which logging should occur.

mapLevelName

public static int mapLevelName(String levelName)
This utility method provides the standard mapping between log4j level names (which Perf4J uses as the standard set of possible levels) to the corresponding ..._LEVEL constant from this class.

Parameters:
levelName - The name of the logging level, should be one of TRACE, DEBUG, INFO, WARN, ERROR or FATAL.
Returns:
The corresponding ..._LEVEL constant from this class.

clone

public CommonsLogStopWatch clone()
Overrides:
clone in class LoggingStopWatch


Copyright © 2008-2009 perf4j.org. All Rights Reserved.