|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--gumbo.util.Debug
Utilities for generating "debug" messages to System.err. To use them, debugging must be enabled and configured; and, "print" messages must be included in your code. Debugging can be enabled and configured by calling methods in your code, or through "-D" system properties passed to the JVM on the command line. To use system properties, call Debug.loadAllProperties() before calling any other debug methods.
The default is for debugging to be disabled. Use setEnabled() or the "-Ddebug.enabled=true" property to enable it. To print debug messages from source code, use one of the print???() methods. Depending on the method used and the system properties set, messages will always be printed (if debug is enabled), will only be printed if a message "tag" is set, will only be printed if a message "object" is set, or if both a message tag and object are set.
Debugging messages can be associated with none or more "tags" and optionally an object (typically "this"). For a message to be printed its tag and object, if any, must be in the "global" tag and object tables. A null tag or object is considered a wild card and will be considered present in its respective table. By default, all objects are printed.
Message tags can be added to the table with addTags() or the command line "-Ddebug.tags=???" property, where "???" is none or more delimited tag names. Message objects can be added to the table with addObj(). There is no command line option to add objects since they are considered runtime entities.
In all cases tags are specified as a list of tag tokens delimited by whitespace, commas, or semicolons. Whitespace is trimmed. Ex: "TAG0 TAG1", "TAG0,TAG1", " TAG0, TAG1 " would parse into tags "TAG0" and "TAG1".
Although no messages are printed if debug is disabled, processing for the message arguments is still performed which can adversely affect performance. As such, all debug print statements should be enclosed in an "if(Debug.getEnabled()) {...}" block.
Constructor Summary | |
Debug()
|
Method Summary | |
static void |
addObj(java.lang.Object obj)
Adds the specified object to the object table. |
static void |
addTags(java.lang.String tags)
Adds the specified tags to the tag table. |
static void |
clearObjs()
Clears the object table. |
static void |
clearTags()
Clears the tag table. |
static boolean |
hasObj(java.lang.Object obj)
Determines if the object is in the object table. |
static boolean |
hasTag(java.lang.String tags)
Determines if any of the tags in the specified tags string are in the tag table. |
static boolean |
isEnabled()
Returns true if debug message printing is enabled. |
static boolean |
loadAllProperties()
Tries to load all Debug system properties. |
static boolean |
loadPropertyAllObjs()
Enables/disables printing all objects according to the "debug.allobjs" system property value. |
static boolean |
loadPropertyAllTags()
Enables/disables printing all tags according to the "debug.alltags" system property value. |
static boolean |
loadPropertyEnabled()
Enables/disables debugging according to the "debug.enabled" system property value. |
static boolean |
loadPropertyTags()
Adds the message tags specified in the "debug.tags" system property to the tag table. |
static boolean |
print(java.lang.Object obj,
java.lang.String tags,
java.lang.String message)
Prints the specified message, without newline, if any of the specified tags are in the tag table and if the object is in the object table. |
static boolean |
print(java.lang.String message)
Prints the specified message, without newline, regardless of the tag table contents. |
static boolean |
print(java.lang.String tags,
java.lang.String message)
Prints the specified message, without newline, if any of the specified tags are in the tag table. |
static boolean |
println(java.lang.Object obj,
java.lang.String tags,
java.lang.String message)
Prints the specified message, with newline, if any of the specified tags are in the tag table. |
static boolean |
println(java.lang.String message)
Prints the specified message, with newline, regardless of the tag table contents. |
static boolean |
println(java.lang.String tags,
java.lang.String message)
Prints the specified message, with newline, if any of the specified tags are in the tag table. |
static void |
removeObj(java.lang.Object obj)
Removes the specified object from the object table. |
static void |
removeTags(java.lang.String tags)
Removes the specified tags from the tag table. |
static void |
setAllObjs(boolean enabled)
Sets whether or not all objects are printed. |
static void |
setAllTags(boolean enabled)
Sets whether or not all tags are printed. |
static void |
setEnabled(boolean enabled)
Sets whether or not debug message printing is enabled. |
static java.lang.String |
toShortString(java.lang.Object obj)
Similar to toString() but the class name is unqualified (returns the remainder of toString() after the last "."). |
static java.lang.String |
toStackTrace(java.lang.Throwable th)
Returns a string containing a throwable's (error, exception) message and stacktrace. |
static java.lang.String |
toString(java.lang.Object obj)
Returns the fully qualified type and hash code (in hex) of an object. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public Debug()
Method Detail |
public static void setEnabled(boolean enabled)
enabled
- True to enable printing.public static boolean isEnabled()
public static void setAllTags(boolean enabled)
enabled
- True to enable printing for all tags.
The default is false.public static void setAllObjs(boolean enabled)
enabled
- True to enable printing for all objects. The
default is true.public static boolean loadPropertyEnabled()
public static boolean loadPropertyAllTags()
public static boolean loadPropertyAllObjs()
public static boolean loadPropertyTags()
public static boolean loadAllProperties()
public static boolean hasTag(java.lang.String tags)
tags
- List of message tags.
public static void addTags(java.lang.String tags)
tags
- List of message tags to be added.public static void removeTags(java.lang.String tags)
tags
- List of message tags to be removed. If a tag
is not in the table it is ignored.public static void clearTags()
public static boolean hasObj(java.lang.Object obj)
obj
- Message object.
public static void addObj(java.lang.Object obj)
obj
- Object to be added.public static void removeObj(java.lang.Object obj)
public static void clearObjs()
public static boolean print(java.lang.String message)
message
- Debug message.
public static boolean println(java.lang.String message)
message
- Debug message.
public static boolean print(java.lang.String tags, java.lang.String message)
tags
- List of message tags. Null for all tags.message
- Debug message.
public static boolean println(java.lang.String tags, java.lang.String message)
tags
- List of message tags. Null for all tags.message
- Debug message.
public static boolean print(java.lang.Object obj, java.lang.String tags, java.lang.String message)
obj
- Message target object. Typically "this".
Null for all targets.tags
- List of message tags. Null for all tags.message
- Debug message.
public static boolean println(java.lang.Object obj, java.lang.String tags, java.lang.String message)
obj
- Message target object. Typically "this".
Null for all targets.tags
- List of message tags. Null for all tags.message
- Debug message.
public static java.lang.String toStackTrace(java.lang.Throwable th)
th
- Target throwable. Never null.
public static java.lang.String toString(java.lang.Object obj)
public static java.lang.String toShortString(java.lang.Object obj)
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |