Purple Code

com.purpletech.util
Class Debug

java.lang.Object
  |
  +--com.purpletech.util.Debug

public class Debug
extends java.lang.Object

Debug utilities To disable logging for a particular log level, call Debug.logger.setLog("err", null)

Version:
1.1
Author:
Alex
See Also:
Logger

Field Summary
static Logger logger
           
 
Constructor Summary
Debug()
           
 
Method Summary
static void assert(boolean check)
          If the given condition is not true, throw an AssertionFailedException
static void assert(boolean check, java.lang.String msg)
           
static void assertTrue(boolean check)
           
static void assertTrue(boolean check, java.lang.String msg)
           
static void debug(java.lang.Object msg)
           
static void err(java.lang.Object msg)
           
static java.lang.String findCaller(java.lang.String ignoreLine, java.lang.Throwable throwable)
           
static java.lang.String findCaller(java.lang.Throwable throwable)
           
static java.lang.String findFileAndLine()
          Calculate what file and line number the Debug package was called from.
static java.lang.String findFileAndLine(java.lang.Throwable throwable)
           
static void info(java.lang.Object msg)
           
static void log(java.lang.Object msg)
           
static void log(java.lang.String which, java.lang.Object msg)
           
static void note(java.lang.Object msg)
           
static void setOptions(Options opts)
          set the logs according to a given set of name=value pairs.
static void warn(java.lang.Object msg)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

public static Logger logger
Constructor Detail

Debug

public Debug()
Method Detail

log

public static void log(java.lang.String which,
                       java.lang.Object msg)

log

public static void log(java.lang.Object msg)

err

public static void err(java.lang.Object msg)

warn

public static void warn(java.lang.Object msg)

note

public static void note(java.lang.Object msg)

info

public static void info(java.lang.Object msg)

debug

public static void debug(java.lang.Object msg)

setOptions

public static void setOptions(Options opts)
set the logs according to a given set of name=value pairs. Each value is either "System.err", "System.out", or a file name


findFileAndLine

public static java.lang.String findFileAndLine()
Calculate what file and line number the Debug package was called from. This is analagous to the use of __LINE__ and __FILE__ macros in popular C debugging packages, although trickier because we have to get the information from the Java runtime. This code is a big ugly hack - the idea is to generate a Throwable, print a stack trace, then walk up the stack trace to find the first line there that does not belong to the Debug package itself. That line should be of the form at edu.mit.media.hive.server.Server.createAgent(Server.java:201) The thing in parentheses is what we want! Obviously, this code relies on the string form of stack traces. It seems to work fine in Sun JDK 1.1.7, other versions may vary. It won't work with a JIT, because this info is not available. Nelson Minar


findFileAndLine

public static java.lang.String findFileAndLine(java.lang.Throwable throwable)

findCaller

public static java.lang.String findCaller(java.lang.Throwable throwable)

findCaller

public static java.lang.String findCaller(java.lang.String ignoreLine,
                                          java.lang.Throwable throwable)

assert

public static void assert(boolean check)
If the given condition is not true, throw an AssertionFailedException


assertTrue

public static void assertTrue(boolean check)

assert

public static void assert(boolean check,
                          java.lang.String msg)

assertTrue

public static void assertTrue(boolean check,
                              java.lang.String msg)

Documentation generated March 5 2003