IMSEVimse 1.0
Draft

se.kth.cid.util
Class Tracer

java.lang.Object
  |
  +--se.kth.cid.util.Tracer

public class Tracer
extends Object

This class is used for debugging and for putting trace printouts in code that may be controlled at runtime.

The printouts are controlled by a global log level When a trace is given to this class, it checks whether the trace is this log level or higher, and then proceeds to print it. Otherwise the trace is simply ignored. Debug traces cannot be turned off, though.

Version:
$Revision: 1.1.1.1 $
Author:
Mikael Nilsson

Field Summary
static int ALL
          Use to get all traces.
static int BUG
          Programming error of some kind, that is only caused by a bug in the program.
static int DEBUG
          Will always be reported.
static int DETAIL
          Details from the inner workings.
static int ERROR
          Serious error in the program, that may be difficult to recover from.
static int MAJOR_EXT_EVENT
          Larger, externally visible event.
static int MAJOR_INT_EVENT
          Larger, internally visible event (implementation dependent)
static int MINOR_EXT_EVENT
          Lesser, externally visible event (e.g.
static int MINOR_INT_EVENT
          Lesser, internally visible event (implementation dependent)
static int NONE
          Use this as log level to never get any traces (except DEBUGs)
static String[] TRACESTR
          Array of the strings that are used to report the above levels.
static int WARNING
          Less serious errors that will not cause immediate problems.
 
Method Summary
static void bug(String trace)
          Used when a bug has been discovered.
static void debug(String trace)
          Used to debug program action.
static void error(String trace)
          Used when a serious error has occured, from which recovery is not foreseen.
static String getTraceStr(int nlogLevel)
          Returns the trace string for the given log level, i.e.
static int parseLogLevel(String level)
          Returns the loglevel represented by the string.
static void setLogLevel(int nlogLevel)
          Used to change the log level.
static void trace(String trace, int thisLogLevel)
          Used to trace program action.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEBUG

public static final int DEBUG
Will always be reported.

BUG

public static final int BUG
Programming error of some kind, that is only caused by a bug in the program. Illegal arguments are included here.

ERROR

public static final int ERROR
Serious error in the program, that may be difficult to recover from. but that can occur without programming errors.

WARNING

public static final int WARNING
Less serious errors that will not cause immediate problems.

MAJOR_EXT_EVENT

public static final int MAJOR_EXT_EVENT
Larger, externally visible event.

MINOR_EXT_EVENT

public static final int MINOR_EXT_EVENT
Lesser, externally visible event (e.g. state change).

MAJOR_INT_EVENT

public static final int MAJOR_INT_EVENT
Larger, internally visible event (implementation dependent)

MINOR_INT_EVENT

public static final int MINOR_INT_EVENT
Lesser, internally visible event (implementation dependent)

DETAIL

public static final int DETAIL
Details from the inner workings. The DETAIL + n levels are allowed, but are defined by the application, and are reported as "DETAILn".

NONE

public static final int NONE
Use this as log level to never get any traces (except DEBUGs)

ALL

public static final int ALL
Use to get all traces.

TRACESTR

public static final String[] TRACESTR
Array of the strings that are used to report the above levels.
Method Detail

parseLogLevel

public static int parseLogLevel(String level)
Returns the loglevel represented by the string.
Parameters:
nLogLevelStr - a string representing a loglevel.
Returns:
the loglevel represented by the string, or -1.
Throws:
IllegalArgumentException - if the loglevel is invalid.

setLogLevel

public static void setLogLevel(int nlogLevel)
Used to change the log level.
Parameters:
nlogLevel - the new log level. Must be positive or zero.

getTraceStr

public static String getTraceStr(int nlogLevel)
Returns the trace string for the given log level, i.e. the string used as label for printouts for traces at this log level.
Parameters:
nlogLevel - the log level to convert to a String.
Returns:
A string representing the log level.

trace

public static void trace(String trace,
                         int thisLogLevel)
Used to trace program action.
Parameters:
trace - the string to display.
thisLogLevel - the loglevel of this trace.

error

public static void error(String trace)
                  throws Error
Used when a serious error has occured, from which recovery is not foreseen. Will throw an Error with the given message, as well as issue a trace with level Tracer.ERROR.
Parameters:
trace - the string to display.
Throws:
Error - always thrown.

bug

public static void bug(String trace)
                throws Error
Used when a bug has been discovered. Will throw an Error with the given message, as well as issue a trace with level Tracer.BUG.
Parameters:
trace - the string to display.
Throws:
Error - always thrown.

debug

public static void debug(String trace)
Used to debug program action. Actually shorthand for
Tracer.trace(trace, Tracer.DEBUG)
Parameters:
trace - the string to display.

IMSEVimse 1.0
Draft

Centre for user-oriented IT -design