Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

abbot
Class Log  view Log download Log.java

java.lang.Object
  extended byabbot.Log

public final class Log
extends java.lang.Object

Various logging, assertion, and debug routines. Typical usage is to include the following code

   public static void main(String[] args) {
  args = Log.init(args)
  ...
   }
   
at an application's main entry point. This way the Log class can remove its options from the full set passed into the application. See the Log.init method for initialization options.

General usage notes on public functions:

Per-class stack trace depth can be specified when adding a class, e.g. classname[:stack-depth].

Version:
$Revision: 1.13 $

Field Summary
private static boolean assertChecks
          Enable assert checks.
private static int CLASS_STACK_DEPTH
          Mnemonic to print the default number of lines of stack trace.
private static java.lang.String classBase
          Strip this out of output, since it doesn't add information to see it repeatedly.
private static java.lang.String dasho
           
private static boolean debugAll
          Debug all classes?
static boolean debugBuild
          Global final to determine whether debugging code is generated.
private static java.util.HashMap debugged
          Store which classes we want to see debug info for.
private static boolean debugInner
          Treat inner/anonymous classes as outer class?
private static int debugStackDepth
          Default number of lines of stack trace to print.
private static java.lang.String DEFAULT_LOGFILE_NAME
           
private static int excStackDepth
          Default number of lines of exception stack trace to print.
private static boolean exitOnAssertionFailure
          Whether to terminate on assertion failures.
static boolean expectDebugOutput
          Whether any debugging output is enabled.
static int FULL_STACK
          Mnemonic to print all lines of a stack trace.
private static java.lang.String lastTimestamp
          Last timestamp written.
private static java.io.PrintStream log
           
private static boolean logMessages
          Whether to log messages.
private static java.util.HashSet notdebugged
          Store which classes we don't want to see debug info for
private static boolean printWarnings
          Whether to print programmer warnings.
private static boolean showThreads
          Whether to show threads in debug output.
private static boolean showTimestamp
          Show timestamps in the log?
private static java.lang.Object synchronizer
          Synchronize message output.
(package private) static java.io.PrintStream systemErr
           
(package private) static java.io.PrintStream systemOut
           
 
Constructor Summary
private Log()
          No instantiations.
 
Method Summary
private static java.lang.String abbreviate(java.lang.String msg)
          Strip out stuff we don't want showing in the message.
private static java.lang.String abbreviate(java.lang.String msg, java.lang.String expr, java.lang.String sub)
          Replace all occurrences of a given expresion with a different string.
static void addDebugClass(java.lang.Class c)
          Indicate the class to add to debug output.
static void addDebugClass(java.lang.Class c, int depth)
          Indicate that debug messages should be output for the given class.
static void addDebugClass(java.lang.String id)
          Indicate the class name[:depth] to add to debug output.
static void assertNotSwing()
          Assert that the current thread is NOT the swing thread.
static void assertSwing()
          Assert that the current thread is the swing thread.
static void assertTrue(boolean test)
          Basic assertion.
static void assertTrue(java.lang.String desc, boolean test)
          Standard assert, with a message provided since java can't easily stringify a boolean expression.
private static void assertTrue(java.lang.String desc, boolean test, int pop)
          Base assert method, for use by all others.
static void close()
           
static void debug()
          Print an empty debug message.
static void debug(java.lang.Class c, java.lang.String event)
          Use this version for performance-critical/high traffic areas
static void debug(java.lang.Object obj)
          Print a debug message using the object given stringified as the message.
static void debug(java.lang.String event)
          Print a debug message.
static void debug(java.lang.String event, int lines)
          Print a debug message with the given number of stack lines.
static void debug(java.lang.Throwable thr)
          Similar to warn(Throwable).
static void enableLogging(java.lang.String filename)
          Enable log output to the given file.
private static java.lang.Class extractClass(java.lang.String trace)
          Return the class corresponding to the first line in the give stack trace.
private static java.lang.Class getClassFromDescriptor(java.lang.String className)
          Returns class from given name/descriptor.
private static int getClassStackDepth(java.lang.Class c)
           
static java.lang.String getStack(int lines)
          Retrieve the given number of lines of the current stack, as a string.
static java.lang.String getStack(int lines, java.lang.Throwable thr)
          Retrieve the given number of lines of stack from the given Throwable, as a string.
private static java.lang.String getStackTrace(int lines)
          Return the requested number of levels of stack trace, not including this call.
private static java.lang.String getStackTrace(int pop, int lines)
          Return the requested number of levels of stack trace, not including this call.
private static java.lang.String getStackTrace(int pop, int lines, java.lang.Throwable thr)
          Return the requested number of levels of stack trace, not including this call.
private static java.lang.String getStackTrace(int pop, java.lang.Throwable thr)
          Return the stack trace contained in the given Throwable.
static java.lang.String[] init(java.lang.String[] args)
          Debug/log initialization, presumably from the command line.
private static void internalDebug(java.lang.Class cls, java.lang.String msg, int lines)
           
private static void internalLog(java.lang.String event)
           
private static void internalWarn(java.lang.String message)
          Issue a warning.
static boolean isClassDebugEnabled(java.lang.Class c)
           
static void log(java.lang.String message)
          Log a message.
static void log(java.lang.Throwable thr)
          Log an exception.
static boolean loggingEnabled()
          Is log output enabled?
static void main(java.lang.String[] args)
          Stack trace/debug unit test.
static void removeDebugClass(java.lang.Class c)
          Indicate that the given class should NOT be debugged (assuming --debug all)
static void removeDebugClass(java.lang.String id)
          Indicate the class name to exclude from debug output.
private static void setDebugClass(java.lang.String id, boolean enable)
          Parse the given string, which may should be of the format "class[:depth]"
static void setDebugStackDepth(int depth)
          Sets the debug stack depth to the given amount
private static java.lang.String trimStackTrace(java.lang.String trace, int lines)
          Trim the given trace to LINES levels.
static void warn(java.lang.String message)
          Issue a programmer warning, which will include the source line of the warning.
static void warn(java.lang.String message, int lines)
          Issue a programmer warning, which will include the source line of the warning, and a stack trace with up to the given number of lines.
static void warn(java.lang.Throwable thr)
          Issue a programmer warning, which will include the source line of the original thrown object.
static void warnIfNotSwing()
          print warning if not invoked on Swing thread
static void warnIfNotSwing(int lines)
          print warning if not invoked on Swing thread, with given number of lines of stack trace.
static void warnInDebug(java.lang.String message)
          Issue a programmer warning, which will include the source line of the warning, but only in debug builds.
static void warnInDebug(java.lang.String message, int lines)
          Issue a programmer warning, which will include the source line of the warning, and a stack trace with up to the given number of lines, but only in debug builds.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

debugBuild

public static final boolean debugBuild
Global final to determine whether debugging code is generated. This should be changed to false to build production code.

See Also:
Constant Field Values

FULL_STACK

public static final int FULL_STACK
Mnemonic to print all lines of a stack trace.

See Also:
Constant Field Values

CLASS_STACK_DEPTH

private static final int CLASS_STACK_DEPTH
Mnemonic to print the default number of lines of stack trace.

See Also:
Constant Field Values

synchronizer

private static java.lang.Object synchronizer
Synchronize message output.


expectDebugOutput

public static boolean expectDebugOutput
Whether any debugging output is enabled.


assertChecks

private static boolean assertChecks
Enable assert checks.


exitOnAssertionFailure

private static boolean exitOnAssertionFailure
Whether to terminate on assertion failures.


logMessages

private static boolean logMessages
Whether to log messages.


printWarnings

private static boolean printWarnings
Whether to print programmer warnings.


showThreads

private static boolean showThreads
Whether to show threads in debug output.


debugStackDepth

private static int debugStackDepth
Default number of lines of stack trace to print.


excStackDepth

private static int excStackDepth
Default number of lines of exception stack trace to print.


showTimestamp

private static boolean showTimestamp
Show timestamps in the log?


lastTimestamp

private static java.lang.String lastTimestamp
Last timestamp written.


classBase

private static final java.lang.String classBase
Strip this out of output, since it doesn't add information to see it repeatedly. Some projects have really long prefixes.


debugged

private static java.util.HashMap debugged
Store which classes we want to see debug info for. FIXME make it a map and make the value the debug level.


notdebugged

private static java.util.HashSet notdebugged
Store which classes we don't want to see debug info for


debugAll

private static boolean debugAll
Debug all classes?


debugInner

private static boolean debugInner
Treat inner/anonymous classes as outer class?


DEFAULT_LOGFILE_NAME

private static final java.lang.String DEFAULT_LOGFILE_NAME
See Also:
Constant Field Values

log

private static java.io.PrintStream log

systemOut

static java.io.PrintStream systemOut

systemErr

static java.io.PrintStream systemErr

dasho

private static final java.lang.String dasho
See Also:
Constant Field Values
Constructor Detail

Log

private Log()
No instantiations.

Method Detail

init

public static java.lang.String[] init(java.lang.String[] args)
Debug/log initialization, presumably from the command line.
Recognized options:
        --debug all | className[:depth] | *.partialClassName[:depth]
        --no-debug className | *.partialClassName
        --log 
        --no-timestamp
        --enable-warnings
        --show-threads
        --stack-depth 
        --exception-depth 
        


loggingEnabled

public static boolean loggingEnabled()
Is log output enabled?


enableLogging

public static void enableLogging(java.lang.String filename)
Enable log output to the given file. "-" means stdout.


setDebugStackDepth

public static void setDebugStackDepth(int depth)
Sets the debug stack depth to the given amount


removeDebugClass

public static void removeDebugClass(java.lang.String id)
Indicate the class name to exclude from debug output.


removeDebugClass

public static void removeDebugClass(java.lang.Class c)
Indicate that the given class should NOT be debugged (assuming --debug all)


addDebugClass

public static void addDebugClass(java.lang.String id)
Indicate the class name[:depth] to add to debug output.


addDebugClass

public static void addDebugClass(java.lang.Class c)
Indicate the class to add to debug output.


addDebugClass

public static void addDebugClass(java.lang.Class c,
                                 int depth)
Indicate that debug messages should be output for the given class.


setDebugClass

private static void setDebugClass(java.lang.String id,
                                  boolean enable)
Parse the given string, which may should be of the format "class[:depth]"


getClassFromDescriptor

private static java.lang.Class getClassFromDescriptor(java.lang.String className)
                                               throws java.lang.ClassNotFoundException
Returns class from given name/descriptor. Descriptor can be either a fully qualified classname, or a classname beginning with *. with client-specific package and classname following.


getStackTrace

private static java.lang.String getStackTrace(int lines)
Return the requested number of levels of stack trace, not including this call. Returns the full stack trace if LINES is FULL_STACK. The outermost call of getStackTrace itself is always removed from the trace.


getStackTrace

private static java.lang.String getStackTrace(int pop,
                                              int lines)
Return the requested number of levels of stack trace, not including this call. Returns the full stack trace if LINES is FULL_STACK. Skip the first POP frames of the trace, which is for excluding the innermost stack frames when debug functions make nested calls. The outermost call of getStackTrace itself is always removed from the trace.


getStackTrace

private static java.lang.String getStackTrace(int pop,
                                              int lines,
                                              java.lang.Throwable thr)
Return the requested number of levels of stack trace, not including this call. Returns the full stack trace if LINES is FULL_STACK. Skip the first POP frames of the trace, which is for excluding the innermost stack frames when debug functions make nested calls. The outermost call of getStackTrace itself is always removed from the trace. Provide an exception to use for the stack trace, rather than using the current program location.


getStackTrace

private static java.lang.String getStackTrace(int pop,
                                              java.lang.Throwable thr)
Return the stack trace contained in the given Throwable. Skip the first POP frames of the trace, which is for excluding the innermost stack frames when debug functions make nested calls. The outermost call of getStackTrace itself is always removed from the trace.


trimStackTrace

private static java.lang.String trimStackTrace(java.lang.String trace,
                                               int lines)
Trim the given trace to LINES levels.


extractClass

private static java.lang.Class extractClass(java.lang.String trace)
Return the class corresponding to the first line in the give stack trace. Treat inner/anonymous classes as the enclosing class.


isClassDebugEnabled

public static boolean isClassDebugEnabled(java.lang.Class c)

getClassStackDepth

private static int getClassStackDepth(java.lang.Class c)

internalDebug

private static void internalDebug(java.lang.Class cls,
                                  java.lang.String msg,
                                  int lines)

debug

public static void debug(java.lang.Class c,
                         java.lang.String event)
Use this version for performance-critical/high traffic areas


debug

public static void debug(java.lang.String event)
Print a debug message.


debug

public static void debug(java.lang.String event,
                         int lines)
Print a debug message with the given number of stack lines.


debug

public static void debug()
Print an empty debug message.


debug

public static void debug(java.lang.Throwable thr)
Similar to warn(Throwable).


debug

public static void debug(java.lang.Object obj)
Print a debug message using the object given stringified as the message.


abbreviate

private static java.lang.String abbreviate(java.lang.String msg,
                                           java.lang.String expr,
                                           java.lang.String sub)
Replace all occurrences of a given expresion with a different string.


abbreviate

private static java.lang.String abbreviate(java.lang.String msg)
Strip out stuff we don't want showing in the message. This includes our package name (it's redundant information), dasho crap, and debug info if a release build.


internalWarn

private static void internalWarn(java.lang.String message)
Issue a warning. All warnings go to the log file and the error stream.


getStack

public static java.lang.String getStack(int lines)
Retrieve the given number of lines of the current stack, as a string.


getStack

public static java.lang.String getStack(int lines,
                                        java.lang.Throwable thr)
Retrieve the given number of lines of stack from the given Throwable, as a string.


warnInDebug

public static void warnInDebug(java.lang.String message)
Issue a programmer warning, which will include the source line of the warning, but only in debug builds.


warnInDebug

public static void warnInDebug(java.lang.String message,
                               int lines)
Issue a programmer warning, which will include the source line of the warning, and a stack trace with up to the given number of lines, but only in debug builds.


warn

public static void warn(java.lang.String message)
Issue a programmer warning, which will include the source line of the warning.


warn

public static void warn(java.lang.String message,
                        int lines)
Issue a programmer warning, which will include the source line of the warning, and a stack trace with up to the given number of lines.


warn

public static void warn(java.lang.Throwable thr)
Issue a programmer warning, which will include the source line of the original thrown object.


assertTrue

private static void assertTrue(java.lang.String desc,
                               boolean test,
                               int pop)
Base assert method, for use by all others. The description should be a description of the condiction if the test is false.


assertTrue

public static void assertTrue(java.lang.String desc,
                              boolean test)
Standard assert, with a message provided since java can't easily stringify a boolean expression.


assertTrue

public static void assertTrue(boolean test)
Basic assertion. Not very useful without a description, though.


assertSwing

public static void assertSwing()
Assert that the current thread is the swing thread.


warnIfNotSwing

public static void warnIfNotSwing(int lines)
print warning if not invoked on Swing thread, with given number of lines of stack trace.


warnIfNotSwing

public static void warnIfNotSwing()
print warning if not invoked on Swing thread


assertNotSwing

public static void assertNotSwing()
Assert that the current thread is NOT the swing thread.


log

public static void log(java.lang.Throwable thr)
Log an exception.


log

public static void log(java.lang.String message)
Log a message.


internalLog

private static void internalLog(java.lang.String event)

close

public static void close()

main

public static void main(java.lang.String[] args)
Stack trace/debug unit test.