iglu.util
Class Debug

java.lang.Object
  |
  +--iglu.util.Debug

public class Debug
extends java.lang.Object

Provides tools for debugging programs. Errors are reported to stderr unless a logfile has been set. If the logfile is set, case all debugging information goes to the file. There are several ways to use this class:

All of these debugging methods are independent, so you may use them in combinations without causing problems. Known Issues: on some JVMs (especially Windows versions), when the stack trace contains "Compiled Code", failed dassertions will report an incorrect failure point. The system for parsing stack traces needs to be tweaked.

Version:
1.0
Author:
Ryan Scherle, Travis Bauer

Field Summary
private static java.lang.String[] debugLevel
           
private static boolean errorsFatal
           
private static java.io.PrintWriter logFileWriter
           
private static boolean quieter
           
private static long timeStamp
           
private static boolean traceOn
           
private static boolean viewAllErrors
           
 
Constructor Summary
private Debug()
           
 
Method Summary
private static void checkFatal()
          Kills the program if errors have been set to fatal.
static void dassert(boolean test)
          If the test is false, prints a message.
static void dassert(boolean test, java.lang.String message)
          If the test is false, prints the message.
static void debugOut(java.lang.String s)
          Send a message to the debugging output stream.
static void debugOut(java.lang.String triggerLevel, int message)
           
static void debugOut(java.lang.String triggerLevel, java.lang.String message)
          Prints a comment if the triggerLevel is one of the active tags, as set by setLevel.
private static java.lang.String getCaller()
          Returns the name of the method that called the debugger.
static boolean isSet(java.lang.String triggerLevel)
          Returns true if the triggerLevel is one of the active tags
static void main(java.lang.String[] args)
          Runs some tests on this class.
static void notImplemented()
          Tells the user that the calling method hasn't been implemented.
static void reportError(java.lang.String message)
          Reports an error, exiting if errors are fatal.
static void reportError(java.lang.String module, java.lang.String message)
          Reports an error, exiting if errors are fatal.
static void setFatal()
          Sets all errors to be fatal.
static void setLevel(java.lang.String[] newLevel)
          Sets list of debugging tags to view.
static void setLevelAll()
          Sets the debugger to view ALL debugging tags.
static void setLogFile(java.io.File logFile)
          Redirects all output to logFile.
static void setQuieter(boolean nQuieter)
          Control verbosity of messages.
static void tic()
          Sets the timer
static double toc()
          Returns the number of seconds transpired since the last time tic() was called.
static void trace(java.lang.String message)
          Prints a message to System.out if tracing mode is on.
static void traceOff()
          Turns tracing mode off.
static void traceOn()
          Turns tracing mode on.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

errorsFatal

private static boolean errorsFatal

traceOn

private static boolean traceOn

logFileWriter

private static java.io.PrintWriter logFileWriter

debugLevel

private static java.lang.String[] debugLevel

quieter

private static boolean quieter

viewAllErrors

private static boolean viewAllErrors

timeStamp

private static long timeStamp
Constructor Detail

Debug

private Debug()
Method Detail

setLogFile

public static void setLogFile(java.io.File logFile)
                       throws java.io.IOException
Redirects all output to logFile.

java.io.IOException

debugOut

public static void debugOut(java.lang.String s)
Send a message to the debugging output stream.


setQuieter

public static void setQuieter(boolean nQuieter)
Control verbosity of messages. If nQuieter is true, messages will be as short as possible. If it is false, all messages will include an indication that they were generated by the Debugging system, along with the the associated level tag, if any.


setFatal

public static void setFatal()
Sets all errors to be fatal. Errors are considered to be failed dassertions or anything reported with setError().


setLevel

public static void setLevel(java.lang.String[] newLevel)
Sets list of debugging tags to view. Any tags in this list will trigger debugging messages that are labeled with the same tag.


setLevelAll

public static void setLevelAll()
Sets the debugger to view ALL debugging tags.


isSet

public static boolean isSet(java.lang.String triggerLevel)
Returns true if the triggerLevel is one of the active tags


debugOut

public static void debugOut(java.lang.String triggerLevel,
                            int message)

debugOut

public static void debugOut(java.lang.String triggerLevel,
                            java.lang.String message)
Prints a comment if the triggerLevel is one of the active tags, as set by setLevel.


traceOn

public static void traceOn()
Turns tracing mode on. Tracing mode is the less-powerful version of tagged debugging. When using tracing, all debugging statements are printed with trace(). These statements can be seen if tracing is on.


traceOff

public static void traceOff()
Turns tracing mode off.


trace

public static void trace(java.lang.String message)
Prints a message to System.out if tracing mode is on. By default, tracing mode is off, so most programs run with minimal output.


notImplemented

public static void notImplemented()
Tells the user that the calling method hasn't been implemented.


dassert

public static void dassert(boolean test)
If the test is false, prints a message.


dassert

public static void dassert(boolean test,
                           java.lang.String message)
If the test is false, prints the message.


getCaller

private static java.lang.String getCaller()
Returns the name of the method that called the debugger. Adapted from ideas by Gregory Rawlins and Dr. Dobb's Journal, January 1998.

The stack should look something like: java.lang.Throwable at iglu.util.Debug.getCaller(Debug.java:155) at iglu.util.Debug.dassert(Debug.java:139) at <> so caller will be on the fourth line of the trace, starting at the fifth character.


reportError

public static void reportError(java.lang.String message)
Reports an error, exiting if errors are fatal. This is similar to calling dassert(false,message)


reportError

public static void reportError(java.lang.String module,
                               java.lang.String message)
Reports an error, exiting if errors are fatal. This is similar to calling dassert(false,message)


checkFatal

private static void checkFatal()
Kills the program if errors have been set to fatal.


tic

public static void tic()
Sets the timer


toc

public static double toc()
Returns the number of seconds transpired since the last time tic() was called.


main

public static void main(java.lang.String[] args)
                 throws java.io.IOException
Runs some tests on this class.

java.io.IOException