Package org.apache.vinci.debug
Class Debug
java.lang.Object
org.apache.vinci.debug.Debug
Miscellaneous debugging functionality such as error logging, assertion checking and exception
reporting. All output produced by this class goes to debugStream which is configurable. This
class is thread safe.
This is JDK1.3 legacy as this functionality is now provided natively by Java 1.4.
-
Method Summary
Modifier and TypeMethodDescriptionstatic void
Assert
(boolean check) Check the provided assertion.static void
Check the provided assertion.static void
flush()
Make sure any messages are flushed to the stream.static PrintStream
Get the debugging stream.static boolean
Determine if exception logging is enabled.static boolean
Determine if message logging is enabled.static String
Same function asprintDebuggingMessage(String)
but easier to type.static void
Same function asprintDebuggingMessage(String,String)
but easier to type.static String
printDebuggingMessage
(String message) Print the provided message to the debug log (if message logging is on).static void
printDebuggingMessage
(String location, String message) Print the provided message to the debug log (if message logging is on).static void
Report the Exception (or Throwable) to the debug log.static void
reportException
(Throwable e, String message) Report the exception to the debug log.static void
Set the debugging stream.static void
setLogExceptions
(boolean on) Turn on/off the logging of reported exceptions.static void
setLogMessages
(boolean on) Set whether debugging messages will be logged to the debug stream.static void
setThreadNameOutput
(boolean on) Turn on/off the reporting of thread name in the debug log.
-
Method Details
-
setDebuggingStream
Set the debugging stream. If no debug stream is explicitly set, then System.err is used.- Parameters:
w
- The stream where debug output will be directed.
-
getDebuggingStream
Get the debugging stream.- Returns:
- The stream currently used for debug output.
-
setLogMessages
public static void setLogMessages(boolean on) Set whether debugging messages will be logged to the debug stream. Default is true.- Parameters:
on
- Whether or not printed debug messages will go to the log.
-
getLogMessages
public static boolean getLogMessages()Determine if message logging is enabled.- Returns:
- true if message logging is enabled
-
setLogExceptions
public static void setLogExceptions(boolean on) Turn on/off the logging of reported exceptions. Default is on.- Parameters:
on
- Whtehr or not reported exceptions will be directed to the log.
-
getLogExceptions
public static boolean getLogExceptions()Determine if exception logging is enabled.- Returns:
- true if message logging is enabled
-
setThreadNameOutput
public static void setThreadNameOutput(boolean on) Turn on/off the reporting of thread name in the debug log. Default is off.- Parameters:
on
- Whether or not the thread name will appear in the output.
-
reportException
Report the exception to the debug log. Usually used to record exceptions that are unexpected, yet do not indicate fatal conditions (e.g. they are recoverable).- Parameters:
e
- The exception to report.message
- Additional information to report along with the exception.
-
reportException
Report the Exception (or Throwable) to the debug log. Usually used to record exceptions that are unexpected, yet do not indicate fatal conditions (e.g. they are recoverable).- Parameters:
e
- The exception to report.
-
printDebuggingMessage
Print the provided message to the debug log (if message logging is on). Does not automatically flush the message to the log. Call flush() if you need to ensure the message is immediately flushed.- Parameters:
message
- The message to report.- Returns:
- The string provided as an argument (to support log chaining).
-
printDebuggingMessage
Print the provided message to the debug log (if message logging is on). Does not automatically flush the message to the log. Call flush() if you need to ensure the message is immediately flushed.- Parameters:
location
- A string indicating which part of code is generating the message.message
- The message to log.
-
p
Same function asprintDebuggingMessage(String)
but easier to type.- Parameters:
message
- -- Returns:
- -
-
p
Same function asprintDebuggingMessage(String,String)
but easier to type.- Parameters:
location
- -message
- -
-
Assert
Check the provided assertion. Used to be named "assert" but renamed to "Assert" to avoid name conflict with the native JDK 1.4 assert function.- Parameters:
check
- The result of the assertion check, which should be false if it fails.- Throws:
AssertionFailedException
- thrown if the method parameter is false.
-
Assert
Check the provided assertion. Used to be named "assert" but renamed to "Assert" to avoid name conflict with the native JDK 1.4 assert function.- Parameters:
check
- Whether or not to throw the exception.message
- A message to include in the thrown exception.- Throws:
AssertionFailedException
- thrown if the condition evaluates to false.
-
flush
public static void flush()Make sure any messages are flushed to the stream. Printing debug messages does not flush the stream automatically, though reporting exceptions does.
-