unsw.cse.mica.util
Class Debug

java.lang.Object
  extended by unsw.cse.mica.util.Debug

public class Debug
extends java.lang.Object

A simple debug utility, implemented as a static class. It controls where debugging output goes as well as the level of debugging output. The lower the debug level, the fewer debug messages are printed.

Author:
Waleed Kadous

Field Summary
static int DEFAULT_LEVEL
           
static int EMERGENCY
           
static int EVERYTHING
           
static int FN_CALLS
           
static int FN_PARAMS
           
static int IMPORTANT
           
static int INFORMATION
           
static int PROGRESS
           
static int TRACE
           
 
Constructor Summary
Debug()
           
 
Method Summary
static void dp(int level, java.lang.String str)
          Prints a debug message, depending on the value of debug level.
static void dpnl(int level, java.lang.String str)
          Prints a multi-line debug message, depending on the value of debug level.
static int getDebugLevel()
          Get the current debug level
static int getDebugLevel(java.lang.String level)
          Get the debug level for a given string.
static java.io.PrintStream getDebugOut()
          Gets the current debug output.
static void myassert(boolean assertion, int l, java.lang.String str)
          An assertion-based error print.
static void myassert(boolean assertion, java.lang.String str)
          An assertion-based error print.
static void setDebugLevel(int debugLvl)
          Set the maximum debug levels.
static void setDebugOut(java.io.PrintStream p)
          Sets the place where all the debug messages go.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

EMERGENCY

public static final int EMERGENCY
See Also:
Constant Field Values

IMPORTANT

public static final int IMPORTANT
See Also:
Constant Field Values

INFORMATION

public static final int INFORMATION
See Also:
Constant Field Values

PROGRESS

public static final int PROGRESS
See Also:
Constant Field Values

FN_CALLS

public static final int FN_CALLS
See Also:
Constant Field Values

FN_PARAMS

public static final int FN_PARAMS
See Also:
Constant Field Values

TRACE

public static final int TRACE
See Also:
Constant Field Values

EVERYTHING

public static final int EVERYTHING
See Also:
Constant Field Values

DEFAULT_LEVEL

public static final int DEFAULT_LEVEL
See Also:
Constant Field Values
Constructor Detail

Debug

public Debug()
Method Detail

getDebugLevel

public static int getDebugLevel(java.lang.String level)
Get the debug level for a given string. The string may be either the name of a level or an integer value (must be >=0 and <= 100). Note that this method does NOT set the debug level, it merely returns the debug level for the correspondign string.

Parameters:
level - The string representation of the level. must be one of "emergency", "important", "information", "progress", "fn_calls", "fn_params", "trace" or "everything".
Returns:
The requested level, or the default level if the given level is not a valid string

setDebugLevel

public static void setDebugLevel(int debugLvl)
Set the maximum debug levels. Any dp(dl, s) method call will only print if it is less than or equal to this level. As a convention, debugLevel 0 should not print any extraneous messages.

Parameters:
debugLvl - New debug level.

getDebugLevel

public static int getDebugLevel()
Get the current debug level

Returns:
The current debug level.

setDebugOut

public static void setDebugOut(java.io.PrintStream p)
Sets the place where all the debug messages go.

Parameters:
p - The PrintStream used to print outputs to.

getDebugOut

public static java.io.PrintStream getDebugOut()
Gets the current debug output.

Returns:
the current debug output stream

dp

public static void dp(int level,
                      java.lang.String str)
Prints a debug message, depending on the value of debug level. If the given debug level is less than or equal to the current debug level, the message is printed. Convention: 0 means this should always be printed; as the number of level gets higher, means it should not be printed unless that level of detail is required.

Parameters:
level - The level of this debug message.
str - The string to be printed.

dpnl

public static void dpnl(int level,
                        java.lang.String str)
Prints a multi-line debug message, depending on the value of debug level. If the given debug level is less than or equal to the current debug level, the message is printed. Convention: 0 means this should always be printed; as the number of level gets higher, means it should not be printed unless that level of detail is required. Each line of the debug output is prefixed by the current datestamp

Parameters:
level - The level of this debug message.
str - The string to be printed.

myassert

public static void myassert(boolean assertion,
                            java.lang.String str)
An assertion-based error print. If the assertion is true, do nothing. If it is false, print it out (at the zero debug level). If If you want level-based assertion, then use the method below.


myassert

public static void myassert(boolean assertion,
                            int l,
                            java.lang.String str)
An assertion-based error print. If the assertion is true, do nothing. If it is false, print it out at the debug level l.