|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectlapisx.util.Debug
Debugging output that can be enabled and disabled on a per-class basis. Using Debug is a three-step process. First, declare a public static (but not final) variable called debug in your class. Its default value should generally be Debug.QUIET:
import lapisx.util.Debug;
public class MyClass {
public static Debug debug = Debug.QUIET;
Second, whenever you want to print debugging output, use the debug
variable instead of System.out or System.err:
debug.println ("this is my debugging message");
// instead of System.err.println()
...
try {
...
} catch (Exception e) {
debug.report (e);
// instead of e.printStackTrace()
...
}
debug.assertion (obj != null);
// to check assertions
Third, when you run your program, use setDebugLevel(java.lang.Class, lapisx.util.Debug) to enable
and disable debugging on a class-by-class basis:
Debug.setDebugLevel (MyClass.class, Debug.VERBOSE);In LAPIS, you can use the -debug command-line parameter to enable debugging output for the classes you want to debug:
lapis -debug MyClass,MyOtherClass,...If you have a set of related classes that are always debugged simultaneously, then you may want them to share a single debug variable for convenience.
| Nested Class Summary | |
static class |
Debug.NoDebug
Debug object that prints nothing and checks no assertions. |
static class |
Debug.Quiet
Debug object that only prints exception stack traces and assertion failures. |
static class |
Debug.Verbose
Debug object that prints all messages, exception stack traces, and checks all assertions. |
| Field Summary | |
static Debug |
NONE
Disables all debugging output and assertion checks. |
static Debug |
QUIET
Enables only exception reports and assertion checks. |
static Debug |
VERBOSE
Enables all debugging output and assertion checks. |
| Constructor Summary | |
Debug()
|
|
| Method Summary | |
abstract void |
assertion(boolean f)
Test an assertion (if this is enabled for assertions) |
abstract boolean |
assertionEnabled()
Test whether calling assertion() on this debug object will do anything. |
static Debug |
getDebugLevel(Class cls)
Get the debugging object currently in use by a class. |
abstract OutputStream |
getOutputStream()
Returns the OutputStream associated with this debug object. |
abstract void |
print(Object obj)
Print an object (if this is enabled for printing) |
abstract void |
print(String message)
Print message (if this is enabled for printing) |
abstract boolean |
printEnabled()
Test whether calling print() or println() on this debug object will print anything. |
abstract void |
println(Object obj)
Print an object (if this is enabled for printing) |
abstract void |
println(String message)
Print message (if this is enabled for printing) |
abstract void |
printStackTrace()
Print stack trace of current execution point (if this is enabled for debugging printing) |
abstract void |
printThreadInfo()
Print a list of active threads (if this is enabled for printing) |
abstract void |
report(Throwable t)
Print the stack trace of an exception (if this is enabled for reporting exceptions) |
abstract boolean |
reportEnabled()
Test whether calling report() on this debug object will print anything. |
static void |
setDebugLevel(Class cls,
Debug level)
Set the debugging object used by a class. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
public static final Debug VERBOSE
public static final Debug QUIET
public static final Debug NONE
| Constructor Detail |
public Debug()
| Method Detail |
public static Debug getDebugLevel(Class cls)
throws NoSuchFieldException
cls - Class to query
NoSuchFieldException - if cls has no public static field named "debug"
public static void setDebugLevel(Class cls,
Debug level)
throws NoSuchFieldException
Debug.setDebugLevel (MyClass.class, Debug.VERBOSE).
cls - Class to modify
NoSuchFieldException - if cls has no public static field named "debug"public abstract boolean printEnabled()
public abstract boolean reportEnabled()
public abstract boolean assertionEnabled()
public abstract void print(String message)
message - message to printpublic abstract void println(String message)
message - message to printpublic abstract void print(Object obj)
obj - object to printpublic abstract void println(Object obj)
obj - object to printpublic abstract void report(Throwable t)
t - exceptionpublic abstract void printThreadInfo()
public abstract void printStackTrace()
public abstract void assertion(boolean f)
f - result of assertion expression
RuntimeException - if assertion fails and this is Verbose.public abstract OutputStream getOutputStream()
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||