Package cx.ath.matthew.debug
Class Debug
java.lang.Object
cx.ath.matthew.debug.Debug
Add debugging to your program, has support for large projects with multiple
classes and debug levels per class. Supports optional enabling of debug
per-level per-class and debug targets of files, Streams or stderr.
Also supports timing between debug outputs, printing of stack traces for Throwables
and files/line numbers on each message.
Debug now automatically figures out which class it was called from, so all methods passing in the calling class are deprecated.
The defaults are to print all messages to stderr with class and method name.
Should be called like this:
if (Debug.debug) Debug.print(Debug.INFO, "Debug Message");
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interface
This interface can be used to provide custom printing filters for certain classes. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final int
Highest priority messagesstatic final boolean
Set this to false to disable compilation of Debug statementsstatic final int
Debug messagesstatic PrintStream
The current output stream (defaults to System.err)static final int
Error messagesstatic final int
Informationstatic final int
Verbose debug messagesstatic final int
Warnings -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic void
Add a filter command for a specific type.static boolean
Deprecated.In Java 1.5 calling class is automatically identified, no need to pass it in.static boolean
static void
loadConfig
(File f) Read which class to debug on at which level from the given File.static void
print
(int loglevel, byte[] b) Log a byte arraystatic void
Log an Objectstatic void
Log a Stringstatic void
Log a Throwablestatic void
Deprecated.In Java 1.5 calling class is automatically identified, no need to pass it in.static void
Deprecated.In Java 1.5 calling class is automatically identified, no need to pass it in.static void
Deprecated.In Java 1.5 calling class is automatically identified, no need to pass it in.static void
Log at DEBUGstatic void
Deprecated.In Java 1.5 calling class is automatically identified, no need to pass it in.static void
Deprecated.In Java 1.5 calling class is automatically identified, no need to pass it in.static void
Deprecated.In Java 1.5 calling class is automatically identified, no need to pass it in.static void
Deprecated.In Java 1.5 calling class is automatically identified, no need to pass it in.static void
Log a Mapstatic void
Deprecated.In Java 1.5 calling class is automatically identified, no need to pass it in.static void
Deprecated.In Java 1.5 calling class is automatically identified, no need to pass it in.static void
Log a Map at DEBUG log levelstatic void
setByteArrayCount
(int count) Set the size of hexdumps.static void
setByteArrayWidth
(int width) Set the formatted width of hexdumps.static void
setHexDump
(boolean hexdump) Enable or disable hexdumps.static void
setLineNos
(boolean lines) Enable or disable line numbers.static void
Output to the default debug.logstatic void
Output to the given Streamstatic void
Output to the given filestatic void
setProperties
(Properties prop) Set properties to configure debugging.static void
setThrowableTraces
(boolean ttrace) Enable or disable stack traces in Debuging throwables.static void
setTiming
(boolean timing) Enable or disable timing in Debug messages.
-
Field Details
-
CRIT
public static final int CRITHighest priority messages- See Also:
-
ERR
public static final int ERRError messages- See Also:
-
WARN
public static final int WARNWarnings- See Also:
-
INFO
public static final int INFOInformation- See Also:
-
DEBUG
public static final int DEBUGDebug messages- See Also:
-
VERBOSE
public static final int VERBOSEVerbose debug messages- See Also:
-
debug
public static final boolean debugSet this to false to disable compilation of Debug statements- See Also:
-
debugout
The current output stream (defaults to System.err)
-
-
Constructor Details
-
Debug
public Debug()
-
-
Method Details
-
setProperties
Set properties to configure debugging. Format of properties is class => level, e.g.cx.ath.matthew.io.TeeOutputStream = INFO cx.ath.matthew.io.DOMPrinter = DEBUG
The debug level can be one of CRIT, ERR, WARN, INFO, DEBUG or VERBOSE which correspond to all messages up to that level. The special words YES, ALL and TRUE cause all messages to be printed regardless of level. All other terms disable messages for that class. CRIT and ERR messages are always printed if debugging is enabled unless explicitly disabled. The special class name ALL can be used to set the default level for all classes.- Parameters:
prop
- Properties object to use.
-
loadConfig
Read which class to debug on at which level from the given File. Syntax the same as Java Properties files:<class> = <debuglevel>
E.G.cx.ath.matthew.io.TeeOutputStream = INFO cx.ath.matthew.io.DOMPrinter = DEBUG
The debug level can be one of CRIT, ERR, WARN, INFO, DEBUG or VERBOSE which correspond to all messages up to that level. The special words YES, ALL and TRUE cause all messages to be printed regardless of level. All other terms disable messages for that class. CRIT and ERR messages are always printed if debugging is enabled unless explicitly disabled. The special class name ALL can be used to set the default level for all classes.- Parameters:
f
- File to read from.- Throws:
IOException
-
debugging
Deprecated.In Java 1.5 calling class is automatically identified, no need to pass it in. -
debugging
-
setOutput
Output to the given Stream- Throws:
IOException
-
setOutput
Output to the given file- Throws:
IOException
-
setOutput
Output to the default debug.log- Throws:
IOException
-
print
Log at DEBUG- Parameters:
d
- The object to log
-
print
Deprecated.In Java 1.5 calling class is automatically identified, no need to pass it in.Log at DEBUG- Parameters:
o
- The object doing the loggingd
- The object to log
-
print
Deprecated.In Java 1.5 calling class is automatically identified, no need to pass it in.Log an Object- Parameters:
o
- The object doing the loggingloglevel
- The level to log at (DEBUG, WARN, etc)d
- The object to log with d.toString()
-
print
Deprecated.In Java 1.5 calling class is automatically identified, no need to pass it in.Log a String- Parameters:
o
- The object doing the loggingloglevel
- The level to log at (DEBUG, WARN, etc)s
- The log message
-
print
Deprecated.In Java 1.5 calling class is automatically identified, no need to pass it in.Log a Throwable- Parameters:
o
- The object doing the loggingloglevel
- The level to log at (DEBUG, WARN, etc)t
- The throwable to log with .toString and .printStackTrace
-
print
Deprecated.In Java 1.5 calling class is automatically identified, no need to pass it in.Log a Throwable- Parameters:
c
- The class doing the loggingloglevel
- The level to log at (DEBUG, WARN, etc)t
- The throwable to log with .toString and .printStackTrace
-
print
Log a Throwable- Parameters:
loglevel
- The level to log at (DEBUG, WARN, etc)t
- The throwable to log with .toString and .printStackTrace- See Also:
-
print
public static void print(int loglevel, byte[] b) Log a byte array- Parameters:
loglevel
- The level to log at (DEBUG, WARN, etc)b
- The byte array to print.- See Also:
-
print
Log a String- Parameters:
loglevel
- The level to log at (DEBUG, WARN, etc)s
- The string to log with d.toString()
-
print
Deprecated.In Java 1.5 calling class is automatically identified, no need to pass it in.Log an Object- Parameters:
c
- The class doing the loggingloglevel
- The level to log at (DEBUG, WARN, etc)d
- The object to log with d.toString()
-
print
Deprecated.In Java 1.5 calling class is automatically identified, no need to pass it in.Log a String- Parameters:
c
- The class doing the loggingloglevel
- The level to log at (DEBUG, WARN, etc)s
- The log message
-
print
Log an Object- Parameters:
loglevel
- The level to log at (DEBUG, WARN, etc)o
- The object to log
-
printMap
Deprecated.In Java 1.5 calling class is automatically identified, no need to pass it in.Log a Map- Parameters:
o
- The object doing the loggingloglevel
- The level to log at (DEBUG, WARN, etc)m
- The Map to print out
-
printMap
Deprecated.In Java 1.5 calling class is automatically identified, no need to pass it in.Log a Map- Parameters:
c
- The class doing the loggingloglevel
- The level to log at (DEBUG, WARN, etc)m
- The Map to print out
-
printMap
Log a Map at DEBUG log level- Parameters:
m
- The Map to print out
-
printMap
Log a Map- Parameters:
loglevel
- The level to log at (DEBUG, WARN, etc)m
- The Map to print out
-
setThrowableTraces
public static void setThrowableTraces(boolean ttrace) Enable or disable stack traces in Debuging throwables. -
setTiming
public static void setTiming(boolean timing) Enable or disable timing in Debug messages. -
setLineNos
public static void setLineNos(boolean lines) Enable or disable line numbers. -
setHexDump
public static void setHexDump(boolean hexdump) Enable or disable hexdumps. -
setByteArrayCount
public static void setByteArrayCount(int count) Set the size of hexdumps. (Default: 36) -
setByteArrayWidth
public static void setByteArrayWidth(int width) Set the formatted width of hexdumps. (Default: 80 chars) -
addFilterCommand
Add a filter command for a specific type. This command will be called with the output stream and the text to be sent. It should perform any changes necessary to the text and then print the result to the output stream.
-