edu.nyu.cs.pdsg.debug
Class Debug

java.lang.Object
  extended byedu.nyu.cs.pdsg.debug.Debug

public class Debug
extends java.lang.Object

Debug parameters can be set on the command line. The Debug command line options are as follows: --debugPrefs PREFERENCES_FILE Reads a file of subsystem-name strings and integer tuples, separated by a ':' character. Any subsystem not named takes the value given for the "GLOBAL" system. See demo01.debug for an example of a basic debug file. --debugLevel INTEGER Sets the "GLOBAL" system level on the command line. How to use debug levels ON STARTUP: The higher the level, the more debug code will be printed. Setting debug level to 10 will print out all levels. Likewise, setting debug level to 0 will print out NOTHING. You can also set the debug level for a specific subsystem. Saving and loading of config files is performed using the saveState and loadState functions respectively. Reseting performed using the reset function. Arguements passed in on the commandline can be checked by using the isDebugArg function, and processed using the configure function. How to use debug levels IN YOUR CODE: Levels 1-4: reserved for testing new code Levels 5-10: Level 5 code will be printed more often than level 10, so choose accordingly More information is available about Debug at http://www.pdsg.cs.nyu.edu/projects.


Field Summary
static boolean debugOff
           
static boolean forceLocalHost
           
private static boolean ignoreRepeats
           
private static java.io.OutputStream logFile
           
private static java.lang.String logFileName
           
private static int logLevel
           
private static java.lang.String[] prevMsgs
           
private static int STACK_HEIGHT
           
private static java.io.OutputStream standardOut
           
private static java.util.HashMap subsystems
           
 
Constructor Summary
Debug()
           
 
Method Summary
private static void configure(java.lang.String commandSwitch, java.lang.String arg)
          Configures Debug using commandline switches
private static java.lang.String[] debugSwitches()
          This is function returns a list of all the debug commandline switches Debug accepts
static java.lang.String getCallingFunction()
           
private static java.lang.String getDebugPrefix(java.lang.StackTraceElement[] stack)
          Returns a string containing the prefix of the debug messages printed
static boolean getIgnoreRepeats()
           
static int getLevel()
          Returns the global level of the Debug class
static int getLevel(java.lang.String _subsystem)
          Returns the given value of specific level or the default value if it doesn't exist
private static double getShortDigitTime()
           
static java.lang.String getStackTrace()
           
static java.lang.String getStackTrace(java.lang.Exception e)
           
private static long getTimeStamp()
          returns the current time as a long
static boolean isDebugArg(java.lang.String commandSwitch)
          Checks to see whether or not a command line switch is a debug command line switch
static void loadState(java.lang.String _fileName)
          Loads a preferences file that contains legal keywords to setup debug modules, global debug levels and log files
private static boolean logic(java.lang.String _subsystem, int _level)
          The logic we use to decide whether or not to display a debug message
static void parseArgs(java.lang.String[] args)
          parses, checks for, and handles Debug argumnents in the main(String args[]) method call
static java.lang.String prettyByteString(byte[] bytes, int offset, int length)
           
static void println(int _level, java.lang.String _debugString)
          print a message at a given debug level
private static void println(java.lang.String _message)
          Tries to print to the given output stream, default System.err
static void println(java.lang.String _subsystem, int _level, java.lang.String _debugString)
          print a message at a given debug level
private static void printlogln(java.lang.String _message)
          Tries to print to the given log file, default null
static void printStackTrace(int _level)
          println, only for current stack trace
static void printStackTrace(int _level, java.lang.Exception _e)
          println, only for exception stack traces
static void printStackTrace(java.lang.String _subsystem, int _level)
          println, only for current stack trace
static void printStackTrace(java.lang.String _subsystem, int _level, java.lang.Exception _e)
          println, only for exception stack traces
static void reset()
          Resets the Debug class to the state it was when the program first started, closing all log files and streams
static void saveState(java.lang.String _fileName)
          Saves the state of the Debug module and its various settings like debug levels and log files
static void setIgnoreRepeats(boolean _ignoreRepeats)
           
static void setLevel(int _level)
          set the current global debug level
static void setLevel(java.lang.String[] _subsystem, int _level)
          Takes an array of subsystem names and sets them all equal to the level given
static void setLevel(java.lang.String[] _subsystem, int[] _level)
          Takes an array subsystem names and levels, and sets each subsystem up to the number of levels available to the corresponding level in the level array, and when it runs out it sets the rest of the subsystems to 0
static void setLevel(java.lang.String _subsystem, int _level)
          Sets a subsystem to a specific level
static void setLogFile(java.lang.String _fileName, int _logLevel)
          Sets the log file to start logging stuff to.
static void setOutputStream(java.io.OutputStream _os)
          Sets the default output stream to whatever is given
private static java.lang.String toHexString(byte n)
          Convert a byte into an hexadecimal number.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

debugOff

public static boolean debugOff

logLevel

private static int logLevel

subsystems

private static java.util.HashMap subsystems

standardOut

private static java.io.OutputStream standardOut

logFile

private static java.io.OutputStream logFile

logFileName

private static java.lang.String logFileName

STACK_HEIGHT

private static int STACK_HEIGHT

prevMsgs

private static java.lang.String[] prevMsgs

ignoreRepeats

private static boolean ignoreRepeats

forceLocalHost

public static boolean forceLocalHost
Constructor Detail

Debug

public Debug()
Method Detail

getStackTrace

public static java.lang.String getStackTrace()

getStackTrace

public static java.lang.String getStackTrace(java.lang.Exception e)

printStackTrace

public static void printStackTrace(int _level)
println, only for current stack trace


printStackTrace

public static void printStackTrace(java.lang.String _subsystem,
                                   int _level)
println, only for current stack trace


printStackTrace

public static void printStackTrace(int _level,
                                   java.lang.Exception _e)
println, only for exception stack traces


printStackTrace

public static void printStackTrace(java.lang.String _subsystem,
                                   int _level,
                                   java.lang.Exception _e)
println, only for exception stack traces


parseArgs

public static void parseArgs(java.lang.String[] args)
parses, checks for, and handles Debug argumnents in the main(String args[]) method call

Parameters:
args - array of command line argument Strings

println

public static void println(int _level,
                           java.lang.String _debugString)
print a message at a given debug level

Parameters:
_level - the level at which to print
_debugString - the string to print

println

public static void println(java.lang.String _subsystem,
                           int _level,
                           java.lang.String _debugString)
print a message at a given debug level

Parameters:
_level - the level at which to print
_debugString - the string to print

println

private static void println(java.lang.String _message)
Tries to print to the given output stream, default System.err


printlogln

private static void printlogln(java.lang.String _message)
Tries to print to the given log file, default null


toHexString

private static final java.lang.String toHexString(byte n)
Convert a byte into an hexadecimal number. The output is always lowercase, two digit long in the range 00-ff.

Example: 12 gives 0c, 18 gives 12, 255 gives ff, ...

Parameters:
n - a byte value to be converted.
Returns:
a two digit hexadecimal number.

prettyByteString

public static java.lang.String prettyByteString(byte[] bytes,
                                                int offset,
                                                int length)

getTimeStamp

private static long getTimeStamp()
returns the current time as a long

Returns:
current time

getShortDigitTime

private static double getShortDigitTime()

setOutputStream

public static void setOutputStream(java.io.OutputStream _os)
Sets the default output stream to whatever is given

Parameters:
_os - is the output stream which all messages of the set levels are printed to

setLogFile

public static void setLogFile(java.lang.String _fileName,
                              int _logLevel)
Sets the log file to start logging stuff to.

Parameters:
_fileName - is a string with the name of the file to log to
_logLevel - is a number which debug messages should not exceed, and is different from the global and module specific debug levels.

getCallingFunction

public static java.lang.String getCallingFunction()

getDebugPrefix

private static java.lang.String getDebugPrefix(java.lang.StackTraceElement[] stack)
Returns a string containing the prefix of the debug messages printed

Returns:
String containing the: class name, the function name, the method name, the file name, and the line number where the message was printed from

logic

private static boolean logic(java.lang.String _subsystem,
                             int _level)
The logic we use to decide whether or not to display a debug message

Parameters:
_subsystem - is the name of the subsystem whose message we wish to print
_level - is the level of the specific message which needs to be checked to see if we print it
Returns:
true if level is less than the level of the subsystem, otherwise false

getLevel

public static int getLevel()
Returns the global level of the Debug class

Returns:
the value of the internal subsystem "GLOBAL"

getLevel

public static int getLevel(java.lang.String _subsystem)
Returns the given value of specific level or the default value if it doesn't exist

Parameters:
_subsystem - is a String with the name of the subsystem whose level we want
Returns:
the level of the given subsystem, or 0 if it doesn't exist

setLevel

public static void setLevel(int _level)
set the current global debug level

Parameters:
_level - the global debug level to go to

setLevel

public static void setLevel(java.lang.String _subsystem,
                            int _level)
Sets a subsystem to a specific level

Parameters:
_subsystem - is the string name of the subsystem
_level - is the the level to associate with the given name

setLevel

public static void setLevel(java.lang.String[] _subsystem,
                            int _level)
Takes an array of subsystem names and sets them all equal to the level given


setIgnoreRepeats

public static void setIgnoreRepeats(boolean _ignoreRepeats)

getIgnoreRepeats

public static boolean getIgnoreRepeats()

setLevel

public static void setLevel(java.lang.String[] _subsystem,
                            int[] _level)
Takes an array subsystem names and levels, and sets each subsystem up to the number of levels available to the corresponding level in the level array, and when it runs out it sets the rest of the subsystems to 0


saveState

public static void saveState(java.lang.String _fileName)
Saves the state of the Debug module and its various settings like debug levels and log files

Parameters:
_fileName - is the name of the file to save these preferences to

loadState

public static void loadState(java.lang.String _fileName)
Loads a preferences file that contains legal keywords to setup debug modules, global debug levels and log files

Parameters:
_fileName - is a string containing the name of the file to load the preferences from.

reset

public static void reset()
Resets the Debug class to the state it was when the program first started, closing all log files and streams


debugSwitches

private static java.lang.String[] debugSwitches()
This is function returns a list of all the debug commandline switches Debug accepts

Returns:
Array of strings which contain all the switches accepted by Debug

isDebugArg

public static boolean isDebugArg(java.lang.String commandSwitch)
Checks to see whether or not a command line switch is a debug command line switch

Parameters:
commandSwitch - a string which contains the exact switch from the command line including the '--'
Returns:
true if arguement is a commandline switch, and false otherwise

configure

private static void configure(java.lang.String commandSwitch,
                              java.lang.String arg)
Configures Debug using commandline switches

Parameters:
commandSwitch - is the switch exactly as given on the commandline
arg - is the arguement given to the switch exactly as given on the commandline


Copyright (c) 2002-2003 New York University RLAB