Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

com.port80.util
Class Debug  view Debug download Debug.java

java.lang.Object
  extended bycom.port80.util.Debug

public class Debug
extends java.lang.Object

Debug mode and related utilities to selectively enable specific debug modes. Debug.set('*') enables all debug modes. Modes 'debug','trace','test','verbose','check' exists by default (but disabled except 'test' is default enabled) on startup and after Debug.clear(). Builtin modes: debug Turns on debug messages. trace Turns on trace messages. test Turns on test messages, which are temporary and would normally remove from source code after the testing. verbose Turns on verbose messages during normal execution. check Turns on check mode code, which provide additional sanity checkings that normal execution should skip. USAGE: . Note that all data and methods are static. . For class that have custom debug mode, it should add the mode in a static initialization block: static { Debug.add("package.classname"); } The added mode by default is disabled. However, if the mode already exist add() would not change its enable/disable state. . The main program is responsible for enabling the specific debug modes by the enable() method. Since the static initialization are executed when the class is loaded, it may be initialized after the main program command line processing. The command line processing can enable specific modes, in that case, the static initialization would be change the enable/disable state. The command line processing call enable() with a wildcard ('*') pattern. In that case, the modes that match the pattern would be enabled when it is added. enable("specific-mode"); // Enable a single mode. enable("wildcard*pattern"); // Enable all existing and future added modes that match the pattern. . There is also disable() methods, however, they should be used sparsely when really neccessary. If there are contradicting enable and disable wildcard patterns, the result is undetermined. . It is the main program's main method repsonsible for enable/disable debugging of a particular module (after checking command line options). . Each module check (static) whether it is required to run in debug mode: public static boolean DEBUG=Debug.isEnabled()||Debug.isEnabled();


Field Summary
private static java.lang.Boolean DISABLE
           
private static java.lang.Boolean ENABLE
           
private static java.util.Map theDefaults
           
private static java.util.Map theModes
           
 
Constructor Summary
Debug()
           
 
Method Summary
static void add(java.lang.String mode)
          Add a mode, by default disabled.
static void add(java.lang.String s, boolean on)
          Add a mode and optionally enable it.
static boolean check()
           
static void clear()
           
static boolean debug()
           
static void disable(java.util.List modes)
          Disable a list of debug mode.
static void disable(java.lang.String modes)
           
static void enable(java.util.List modes)
          Enable a list of debug modes.
static void enable(java.lang.String modes)
           
static boolean get(java.lang.String s)
           
static java.util.List getDisables()
          Return the name of all debug modes that are disabled.
static java.util.List getEnables()
          Return the name of all debug modes that are enabled.
static java.util.List getModes()
          Return the name of all declared debug modes.
private static void init()
           
static boolean isCheck()
           
static boolean isDebug()
           
static boolean isEnabled(java.lang.String s)
           
static boolean isOn()
           
static boolean isTest()
           
static boolean isTrace()
           
static boolean isVerbose()
           
static boolean on()
           
static void reset(java.lang.String s)
           
static void set(java.lang.String s)
          Same as enable(),disable(),isEnabled(),isDebug()...etc.
static boolean test()
           
static boolean trace()
           
static boolean verbose()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ENABLE

private static final java.lang.Boolean ENABLE

DISABLE

private static final java.lang.Boolean DISABLE

theModes

private static java.util.Map theModes

theDefaults

private static java.util.Map theDefaults
Constructor Detail

Debug

public Debug()
Method Detail

clear

public static void clear()

enable

public static void enable(java.util.List modes)
Enable a list of debug modes.


enable

public static void enable(java.lang.String modes)

disable

public static void disable(java.util.List modes)
Disable a list of debug mode.


disable

public static void disable(java.lang.String modes)

add

public static void add(java.lang.String mode)
Add a mode, by default disabled. If the mode already exist, its enable/disable state would not be changed. If the mode match any wildcard patterns (specified in previous enable() or disable() calls), it would be enable/disabled accordingly.


add

public static void add(java.lang.String s,
                       boolean on)
Add a mode and optionally enable it.


getModes

public static java.util.List getModes()
Return the name of all declared debug modes.


getEnables

public static java.util.List getEnables()
Return the name of all debug modes that are enabled.


getDisables

public static java.util.List getDisables()
Return the name of all debug modes that are disabled.


isEnabled

public static boolean isEnabled(java.lang.String s)

isOn

public static boolean isOn()

isDebug

public static boolean isDebug()

isTrace

public static boolean isTrace()

isTest

public static boolean isTest()

isVerbose

public static boolean isVerbose()

isCheck

public static boolean isCheck()

set

public static void set(java.lang.String s)
Same as enable(),disable(),isEnabled(),isDebug()...etc.


reset

public static void reset(java.lang.String s)

get

public static boolean get(java.lang.String s)

on

public static boolean on()

debug

public static boolean debug()

trace

public static boolean trace()

test

public static boolean test()

verbose

public static boolean verbose()

check

public static boolean check()

init

private static void init()