org.jlf.log
Class AppInstrument

java.lang.Object
  |
  +--org.jlf.log.AppInstrument
Direct Known Subclasses:
DataMapInstrument

public class AppInstrument
extends java.lang.Object

This class provides a timer utility to instrument your application. When you create a new instance of this class, it starts a timer before returning. Then do some work in your application and when you want to stop the timer and output the result to the log, call the logTime() method.

See Also:
Log

Field Summary
protected  long alertTimeOutMilliseconds
          Holds a time out value in milliseconds.
protected  java.lang.String instrumentedEventName
          Holds the String which will be output to the log as a prefix to the time it takes to perform the actions the instrumented time.
protected  int outputAlertLoggingLevel
          Holds the alert logging level for the Log when an instrumented event goes beyond its time out value.
protected  Log outputLog
          Holds the Log you will output the time to.
protected  int outputLoggingLevel
          Holds the logging level for the Log when writing the log entry out.
protected  long startTime
          Holds the start time from when the instance was created.
 
Constructor Summary
protected AppInstrument()
          Protect the default constructor, use a parameterized constructor below!
  AppInstrument(java.lang.String instrumentedEventName)
          Constructor which accepts the name of the event you are going to instrument.
  AppInstrument(java.lang.String instrumentedEventName, int loggingLevel)
          Constructor which accepts the name of the event you are going to instrument and the logging level you are going to log to.
  AppInstrument(java.lang.String instrumentedEventName, int loggingLevel, long alertTimeOutMilliseconds)
          Constructor which accepts the name of the event you are going to instrument, the normal logging level, and a timeout value that if exceeded changes the logging level to the alert status.
  AppInstrument(java.lang.String instrumentedEventName, Log log)
          Constructor which accepts the name of the event you are going to instrument and the log you are going to log to.
  AppInstrument(java.lang.String instrumentedEventName, Log log, int loggingLevel)
          Constructor which accepts the name of the event you are going to instrument and the log you are going to log to, and the logging level.
  AppInstrument(java.lang.String instrumentedEventName, Log log, int loggingLevel, int alertLoggingLevel, long alertTimeOutMilliseconds)
          Constructor which accepts all parameters for creating an instrument.
 
Method Summary
protected static int getDefaultAlertLoggingLevel()
          Returns the default logging level to log to when writing the output of the instrument.
protected static long getDefaultAlertTimeOutMilliseconds()
          Returns the default alert time out value, set to zero, so that an event does not time out and raise its logging level to an error status.
protected static Log getDefaultLog()
          Returns the default Log to log to when writing the output of the instrument.
protected static int getDefaultLoggingLevel()
          Returns the default logging level to log to when writing the output of the instrument.
 long logTime()
          Logs the time since the timer was started to the log and logging level set when the instrument was created.
 long logTime(java.lang.String instrumentedEventName)
          Logs the time since the timer was started to the log and logging level set when the instrument was created, sets/resets the instrumented event string to the input string.
 void resetTimer()
          Resets the timer so that you can re-use the same AppInstrument object to time different events.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

instrumentedEventName

protected java.lang.String instrumentedEventName
Holds the String which will be output to the log as a prefix to the time it takes to perform the actions the instrumented time.


outputLog

protected Log outputLog
Holds the Log you will output the time to.


alertTimeOutMilliseconds

protected long alertTimeOutMilliseconds
Holds a time out value in milliseconds. If this value is a positive number, the timer is checked to see if it exceeds this value. If so, instead of using outputLoggingLevel as a logging level, the instrument will use outputAlertLoggingLevel.


outputLoggingLevel

protected int outputLoggingLevel
Holds the logging level for the Log when writing the log entry out.


outputAlertLoggingLevel

protected int outputAlertLoggingLevel
Holds the alert logging level for the Log when an instrumented event goes beyond its time out value.


startTime

protected long startTime
Holds the start time from when the instance was created.

Constructor Detail

AppInstrument

protected AppInstrument()
Protect the default constructor, use a parameterized constructor below!


AppInstrument

public AppInstrument(java.lang.String instrumentedEventName)
Constructor which accepts the name of the event you are going to instrument. Uses defaults for all other values.


AppInstrument

public AppInstrument(java.lang.String instrumentedEventName,
                     int loggingLevel)
Constructor which accepts the name of the event you are going to instrument and the logging level you are going to log to. Uses defaults for all other values.


AppInstrument

public AppInstrument(java.lang.String instrumentedEventName,
                     Log log)
Constructor which accepts the name of the event you are going to instrument and the log you are going to log to. Uses defaults for all other values.


AppInstrument

public AppInstrument(java.lang.String instrumentedEventName,
                     Log log,
                     int loggingLevel)
Constructor which accepts the name of the event you are going to instrument and the log you are going to log to, and the logging level. Uses defaults for all other values.


AppInstrument

public AppInstrument(java.lang.String instrumentedEventName,
                     int loggingLevel,
                     long alertTimeOutMilliseconds)
Constructor which accepts the name of the event you are going to instrument, the normal logging level, and a timeout value that if exceeded changes the logging level to the alert status.


AppInstrument

public AppInstrument(java.lang.String instrumentedEventName,
                     Log log,
                     int loggingLevel,
                     int alertLoggingLevel,
                     long alertTimeOutMilliseconds)
Constructor which accepts all parameters for creating an instrument. Starts the timer before returning. Note to subclassers: This method MUST eventually be called or the class will not function properly!

Method Detail

getDefaultLog

protected static Log getDefaultLog()
Returns the default Log to log to when writing the output of the instrument. The default for this class is AppLog.


getDefaultLoggingLevel

protected static int getDefaultLoggingLevel()
Returns the default logging level to log to when writing the output of the instrument. The default for this class is detail level.


getDefaultAlertLoggingLevel

protected static int getDefaultAlertLoggingLevel()
Returns the default logging level to log to when writing the output of the instrument. The default for this class is detail level.


getDefaultAlertTimeOutMilliseconds

protected static long getDefaultAlertTimeOutMilliseconds()
Returns the default alert time out value, set to zero, so that an event does not time out and raise its logging level to an error status.


logTime

public long logTime()
Logs the time since the timer was started to the log and logging level set when the instrument was created.


logTime

public long logTime(java.lang.String instrumentedEventName)
Logs the time since the timer was started to the log and logging level set when the instrument was created, sets/resets the instrumented event string to the input string.


resetTimer

public void resetTimer()
Resets the timer so that you can re-use the same AppInstrument object to time different events.