|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.perf4j.StopWatch
org.perf4j.LoggingStopWatch
org.perf4j.javalog.JavaLogStopWatch
public class JavaLogStopWatch
This LoggingStopWatch uses a java.util.logging Logger to persist the StopWatch messages. The various constructors allow you to specify the Logger to use (defaults to org.perf4j.TimingLogger), the Level at which messages are normally logged (defaults to INFO) and the Level used for logging if one of the stop or lap methods that takes an exception is called (defaults to WARNING).
Field Summary |
---|
Fields inherited from class org.perf4j.StopWatch |
---|
DEFAULT_LOGGER_NAME |
Constructor Summary | |
---|---|
JavaLogStopWatch()
Creates a JavaLogStopWatch with a blank tag, no message and started at the instant of creation. |
|
JavaLogStopWatch(Logger logger)
Creates a JavaLogStopWatch with a blank tag, no message and started at the instant of creation, using the specified Logger to log stop watch messages at the INFO level, or at the WARNING level if an exception is passed to one of the stop or lap methods. |
|
JavaLogStopWatch(Logger logger,
Level normalPriority)
Creates a JavaLogStopWatch with a blank tag, no message and started at the instant of creation, using the specified Logger to log stop watch messages at the normalPriority level specified, or at the WARNING level if an exception is passed to one of the stop or lap methods. |
|
JavaLogStopWatch(Logger logger,
Level normalPriority,
Level exceptionPriority)
Creates a JavaLogStopWatch with a blank tag, no message and started at the instant of creation, using the specified Logger 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. |
|
JavaLogStopWatch(long startTime,
long elapsedTime,
String tag,
String message,
Logger logger,
Level normalPriority,
Level exceptionPriority)
This constructor is mainly used for creation of StopWatch instances from logs and for testing. |
|
JavaLogStopWatch(String tag)
Creates a JavaLogStopWatch with the tag specified, no message and started at the instant of creation. |
|
JavaLogStopWatch(String tag,
Logger logger)
Creates a JavaLogStopWatch with the tag specified, no message and started at the instant of creation, using the specified Logger to log stop watch messages at INFO level, or at the WARNING level if an exception is passed to one of the stop or lap methods. |
|
JavaLogStopWatch(String tag,
Logger logger,
Level normalPriority)
Creates a JavaLogStopWatch with the tag specified, no message and started at the instant of creation, using the specified Logger to log stop watch messages at the normalPriority level specified, or at the WARNING level if an exception is passed to one of the stop or lap methods. |
|
JavaLogStopWatch(String tag,
Logger logger,
Level normalPriority,
Level exceptionPriority)
Creates a JavaLogStopWatch with the tag specified, no message and started at the instant of creation, using the specified Logger 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. |
|
JavaLogStopWatch(String tag,
String message)
Creates a JavaLogStopWatch with the tag and message specified and started at the instant of creation. |
|
JavaLogStopWatch(String tag,
String message,
Logger logger)
Creates a JavaLogStopWatch with the tag and message specified and started at the instant of creation, using the specified Logger to log stop watch messages at INFO level, or at WARNING level if an exception is passed to one of the stop or lap methods. |
|
JavaLogStopWatch(String tag,
String message,
Logger logger,
Level normalPriority)
Creates a JavaLogStopWatch with the tag and message specified and started at the instant of creation, using the specified Logger to log stop watch messages at the normalPriority level specified, or at WARNING level if an exception is passed to one of the stop or lap methods. |
|
JavaLogStopWatch(String tag,
String message,
Logger logger,
Level normalPriority,
Level exceptionPriority)
Creates a JavaLogStopWatch with the tag and message specified and started at the instant of creation, using the specified Logger 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 | |
---|---|
JavaLogStopWatch |
clone()
|
Level |
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. |
Logger |
getLogger()
Gets the java.util.logging Logger that is used to persist logging statements when one of the stop or lap methods is called. |
Level |
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 logger it uses is enabled at the normalPriority level of this StopWatch. |
protected void |
log(String stopWatchAsString,
Throwable exception)
The log message is overridden to use the java.util.logging Logger to persist the stop watch. |
static Level |
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 closest corresponding java.util.logging Level. |
JavaLogStopWatch |
setExceptionPriority(Level 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. |
JavaLogStopWatch |
setLogger(Logger logger)
Sets the java.util.logging Logger used to persist StopWatch instances. |
JavaLogStopWatch |
setMessage(String message)
Sends a message on this StopWatch instance to be printed when this instance is logged. |
JavaLogStopWatch |
setNormalAndSlowSuffixesEnabled(boolean normalAndSlowSuffixesEnabled)
Sets whether to append normalSuffix and slowSuffix when timeThreshold > 0 AND elapsedTime >= timeThreshold |
JavaLogStopWatch |
setNormalPriority(Level 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. |
JavaLogStopWatch |
setNormalSuffix(String normalSuffix)
Sets the suffix to use when normalAndSlowSuffixesEnabled=true and timeThreshold > 0 and elapsedTime < timeThreshold. |
JavaLogStopWatch |
setSlowSuffix(String slowSuffix)
Sets the suffix to use when normalAndSlowSuffixesEnabled=true and timeThreshold > 0 and elapsedTime >= timeThreshold. |
JavaLogStopWatch |
setTag(String tag)
Sets the grouping tag for this StopWatch instance. |
JavaLogStopWatch |
setTimeThreshold(long timeThreshold)
Sets a threshold level, in milliseconds, below which logging calls will not be made. |
Methods inherited from class org.perf4j.LoggingStopWatch |
---|
getNormalSuffix, getSlowSuffix, getTag, getTimeThreshold, isNormalAndSlowSuffixesEnabled, lap, lap, stop, stop, stop, stop |
Methods inherited from class org.perf4j.StopWatch |
---|
equals, getElapsedTime, getMessage, getStartTime, hashCode, lap, lap, start, start, start, stop, stop, toString |
Methods inherited from class java.lang.Object |
---|
finalize, getClass, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public JavaLogStopWatch()
public JavaLogStopWatch(Logger logger)
logger
- The Logger to use when persisting StopWatches in one of the stop or lap methods.public JavaLogStopWatch(Logger logger, Level normalPriority)
logger
- The Logger 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.public JavaLogStopWatch(Logger logger, Level normalPriority, Level exceptionPriority)
logger
- The Logger 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.public JavaLogStopWatch(String tag)
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.public JavaLogStopWatch(String tag, Logger logger)
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 Logger to use when persisting StopWatches in one of the stop or lap methods.public JavaLogStopWatch(String tag, Logger logger, Level normalPriority)
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 Logger 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.public JavaLogStopWatch(String tag, Logger logger, Level normalPriority, Level exceptionPriority)
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 Logger 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.public JavaLogStopWatch(String tag, String message)
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.public JavaLogStopWatch(String tag, String message, Logger logger)
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 Logger to use when persisting StopWatches in one of the stop or lap methods.public JavaLogStopWatch(String tag, String message, Logger logger, Level normalPriority)
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 Logger 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.public JavaLogStopWatch(String tag, String message, Logger logger, Level normalPriority, Level exceptionPriority)
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 Logger 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.public JavaLogStopWatch(long startTime, long elapsedTime, String tag, String message, Logger logger, Level normalPriority, Level exceptionPriority)
startTime
- The start time in millisecondselapsedTime
- The elapsed time in millisecondstag
- The tag used to group timing logs of the same code blockmessage
- Additional message textlogger
- The Logger 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 |
---|
public Logger getLogger()
public JavaLogStopWatch setLogger(Logger logger)
logger
- The Logger this instance should use for persistence. May not be null.
public Level getNormalPriority()
public JavaLogStopWatch setNormalPriority(Level normalPriority)
normalPriority
- The Level used when logging "normal" stop or lap calls. May not be null.
public Level getExceptionPriority()
public JavaLogStopWatch setExceptionPriority(Level exceptionPriority)
exceptionPriority
- The Level used when logging "exceptional" stop or lap calls. May not be null.
public JavaLogStopWatch setTimeThreshold(long timeThreshold)
LoggingStopWatch
JmxAttributeStatisticsAppender
in the logging configuration to be notified when
times are outside acceptable thresholds.
setTimeThreshold
in class LoggingStopWatch
timeThreshold
- The minimum elapsed time, in milliseconds, below which log calls will not be made.
JmxAttributeStatisticsAppender.getNotificationThresholds()
public JavaLogStopWatch setTag(String tag)
StopWatch
setTag
in class LoggingStopWatch
tag
- The grouping tag.
public JavaLogStopWatch setMessage(String message)
StopWatch
setMessage
in class LoggingStopWatch
message
- The message associated with this StopWatch, which may be null.
public JavaLogStopWatch setNormalAndSlowSuffixesEnabled(boolean normalAndSlowSuffixesEnabled)
LoggingStopWatch
setNormalAndSlowSuffixesEnabled
in class LoggingStopWatch
normalAndSlowSuffixesEnabled
- true enables logging extra suffixes to normal and slow events; false (default) suppresses the suffixespublic JavaLogStopWatch setNormalSuffix(String normalSuffix)
LoggingStopWatch
setNormalSuffix
in class LoggingStopWatch
normalSuffix
- the suffix to append if normalAndSlowSuffixesEnabled and the elapsedtime is under the thresholdpublic JavaLogStopWatch setSlowSuffix(String slowSuffix)
LoggingStopWatch
setSlowSuffix
in class LoggingStopWatch
slowSuffix
- the suffix to append if normalAndSlowSuffixesEnabled and the elapsedtime is under the thresholdpublic boolean isLogging()
isLogging
in class LoggingStopWatch
protected void log(String stopWatchAsString, Throwable exception)
log
in class LoggingStopWatch
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.public static Level mapLevelName(String levelName)
levelName
- The name of the logging level, should be one of TRACE, DEBUG, INFO, WARN, ERROR or FATAL.
public JavaLogStopWatch clone()
clone
in class LoggingStopWatch
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |