net.xoetrope.debug
Class DebugLogger

java.lang.Object
  extended by net.xoetrope.debug.DebugLogger

public class DebugLogger
extends java.lang.Object

Keep track of errors and waranings. The class is implemented as a singleton so that it can count the errors and warnings and give some statistics when the application shutsdown as a debugging aid.

Copyright (c) Xoetrope Ltd., 2002-2005

$Revision: 2.4 $ License: see license.txt


Field Summary
static int DEBUG
          output errors, dumps and exit messages
static int NORMAL
          only output error messages
static int PARANOID
          output all logging information
static int SILENT
          do not log anything
static int VERBOSE
          output debug messages, errors, dumps, exit massages, traces and log values
 
Constructor Summary
protected DebugLogger()
           
 
Method Summary
static void dump()
          Display log counts for warnings and errors
static void dumpModel(XModel model)
          Write a representation of the model to the console.
static void enableZone(java.lang.String zone, boolean state)
          Enable/disable a debug zone
static void exitApplication()
          On exit this method will dump the contents of the debug log and close the VM
static DebugLogger getInstance()
          Get the logger instance
static boolean isZoneEnabled(java.lang.String zone)
          Check if a debug zone is enabled
static void log(java.lang.String msg)
          Write a message to the log
static void logError(java.lang.String error)
          Write an error message to the error stream.
static void logError(java.lang.String zone, java.lang.String error)
          Write an error message to the error stream.
static void logWarning(java.lang.String warning)
          Write a warning message to the console.
static void logWarning(java.lang.String zone, java.lang.String warning)
          Write a warning message to the console.
static void readLoggerZones(XProject currentProject)
          Read the debug zones file ("DebugZones.properties")
static void setDebugLevel(int newLevel)
          Set the logging level, by default the level is verbose
NORMAL = 0, only output error messages
DEBUG = 1, output errors, dumps and exit messages
VERBOSE = 2, output debug messages, errors, dumps, exit massages, traces and log values
PARANOID = 3, output all logging information
static void setDebugLevel(java.lang.String newLevel)
          Set the logging level, by default the level is verbose
SILENT = -1, do not log anything NORMAL = 0, only output error messages
DEBUG = 1, output errors, dumps and exit messages
VERBOSE = 2, output debug messages, errors, dumps, exit massages, traces and log values
PARANOID = 3, output all logging information
static void setErrorWriter(XLogWriter writer)
          Set the writer for the error output stream
static void setLogListener(XLogListener logger)
          Set a listener for log messsages
static void setOutputWriter(XLogWriter writer)
          Set the writer for the output stream
static void trace(java.lang.String msg)
          Write a message to the console.
static void trace(java.lang.String msg, double value)
          Write a message to the console.
static void trace(java.lang.String zone, java.lang.String msg)
          Write a message to the console.
static void trace(XProject currentProject, XModel model)
          Write a snapshot of a model or model fragment to the log
protected static void writeErrorLine(java.lang.String line)
          Write an error line to the system error stream and log the message
protected static void writeLine(java.lang.String line)
          Write a line to the system output and log the message
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SILENT

public static final int SILENT
do not log anything

See Also:
Constant Field Values

NORMAL

public static final int NORMAL
only output error messages

See Also:
Constant Field Values

DEBUG

public static final int DEBUG
output errors, dumps and exit messages

See Also:
Constant Field Values

VERBOSE

public static final int VERBOSE
output debug messages, errors, dumps, exit massages, traces and log values

See Also:
Constant Field Values

PARANOID

public static final int PARANOID
output all logging information

See Also:
Constant Field Values
Constructor Detail

DebugLogger

protected DebugLogger()
Method Detail

exitApplication

public static void exitApplication()
On exit this method will dump the contents of the debug log and close the VM


dump

public static void dump()
Display log counts for warnings and errors


getInstance

public static DebugLogger getInstance()
Get the logger instance

Returns:
the DebugLogger instance

logError

public static void logError(java.lang.String zone,
                            java.lang.String error)
Write an error message to the error stream. Errors are logged unless the logLevel is SILENT

Parameters:
error - the error message
zone - the zone name

logError

public static void logError(java.lang.String error)
Write an error message to the error stream. Errors are logged unless the logLevel is SILENT

Parameters:
error - the error message

logWarning

public static void logWarning(java.lang.String zone,
                              java.lang.String warning)
Write a warning message to the console. Warnings are logged unless the logLevel is less than DEBUG or unless the DEBUG build property is set to false

Parameters:
zone - the zone name
warning - the warning message

logWarning

public static void logWarning(java.lang.String warning)
Write a warning message to the console. Warnings are logged unless the logLevel is less than DEBUG or unless the DEBUG build property is set to false

Parameters:
warning - the warning message

log

public static void log(java.lang.String msg)
Write a message to the log

Parameters:
msg - the message to log

trace

public static void trace(java.lang.String zone,
                         java.lang.String msg)
Write a message to the console. Trace messages are logged unless the logLevel is less than VERBOSE or unless the DEBUG build property is set to false

Parameters:
zone - the zone name
msg - the log message

trace

public static void trace(java.lang.String msg)
Write a message to the console. Trace messages are logged unless the logLevel is less than VERBOSE or unless the DEBUG build property is set to false

Parameters:
msg - the log message

trace

public static void trace(java.lang.String msg,
                         double value)
Write a message to the console. The message is assumed to have a substitution for a numeric value e.g. 'TRACE: The X value is VALUE: 1.09' Trace messages are logged unless the logLevel is less than VERBOSE or unless the DEBUG build property is set to false

Parameters:
msg - the log message
value - the value causing the trace

trace

public static void trace(XProject currentProject,
                         XModel model)
Write a snapshot of a model or model fragment to the log

Parameters:
currentProject - the owner project
model - the model node to log

dumpModel

public static void dumpModel(XModel model)
Write a representation of the model to the console.

Parameters:
model - the model node to dump

setDebugLevel

public static void setDebugLevel(int newLevel)
Set the logging level, by default the level is verbose
NORMAL = 0, only output error messages
DEBUG = 1, output errors, dumps and exit messages
VERBOSE = 2, output debug messages, errors, dumps, exit massages, traces and log values
PARANOID = 3, output all logging information

Parameters:
newLevel - the new log level

setDebugLevel

public static void setDebugLevel(java.lang.String newLevel)
Set the logging level, by default the level is verbose
SILENT = -1, do not log anything NORMAL = 0, only output error messages
DEBUG = 1, output errors, dumps and exit messages
VERBOSE = 2, output debug messages, errors, dumps, exit massages, traces and log values
PARANOID = 3, output all logging information

Parameters:
newLevel - the new log level

isZoneEnabled

public static boolean isZoneEnabled(java.lang.String zone)
Check if a debug zone is enabled

Parameters:
zone - the zone name
Returns:
true if the zone is enabled

enableZone

public static void enableZone(java.lang.String zone,
                              boolean state)
Enable/disable a debug zone

Parameters:
state - true to enable the zone, false otherwise
zone - the zone name

writeLine

protected static void writeLine(java.lang.String line)
Write a line to the system output and log the message

Parameters:
line - the message to log

writeErrorLine

protected static void writeErrorLine(java.lang.String line)
Write an error line to the system error stream and log the message

Parameters:
line - the message to log

setLogListener

public static void setLogListener(XLogListener logger)
Set a listener for log messsages

Parameters:
logger - the listener

setOutputWriter

public static void setOutputWriter(XLogWriter writer)
Set the writer for the output stream


setErrorWriter

public static void setErrorWriter(XLogWriter writer)
Set the writer for the error output stream


readLoggerZones

public static void readLoggerZones(XProject currentProject)
Read the debug zones file ("DebugZones.properties")

Parameters:
currentProject - the owner project