maslab.util
Class Logger

java.lang.Object
  extended by maslab.util.Logger

public class Logger
extends java.lang.Object

A simple logging facility designed for all of a program's textual output. Output sources are categorized by "channel names", typically on a per-class basis. Output can be redirected arbitrarily by providing publishers.


Field Summary
static ConsoleLoggerPublisher consolePublisher
           
static int DEBUG
          extensive debugging information
static int ERROR
          failure has occurred, typically fatal
static int OUTPUT
          the expected output of the program.
static int SILENT
          Used only by LoggerPublishers: indicates that no messages should be published.
static long startTime
           
static int VDEBUG
          ludicrous quantities of debug information
static int VERBOSE
          occasional status messages
static int VVERBOSE
          more frequent status messages
static int WARN
          a recoverable failure has occurred, or something suspicious occured.
 
Constructor Summary
Logger(java.lang.Object o)
          Create a logger which will take its name as the class name of the argument.
Logger(java.lang.String name)
          Create a new logger with the specified name.
 
Method Summary
static void addPublisher(LoggerPublisher publisher)
          Add a new publisher
 void debug(java.lang.String message)
          A convenience method
 void error(java.lang.String message)
          A convenience method
 void error(java.lang.String message, java.lang.Exception ex)
          A convenience method
static java.lang.String levelToString(int level)
          Convert an integer value corresponding to a debug level into a human-readable string, e.g.
 void log(int level, java.lang.String message)
          Log a message for this channel
 void log(int level, java.lang.String message, java.lang.Exception ex)
          Log a message for this channel
static void log(java.lang.String name, int level, java.lang.String message)
          The actual log method.
static void log(java.lang.String name, int level, java.lang.String message, java.lang.Exception ex)
          Produce a log message containing information about an exception that occured.
static void main(java.lang.String[] args)
           
 void output(java.lang.String message)
          A convenience method
 void output(java.lang.String message, java.lang.Exception ex)
          A convenience method
static void removePublisher(LoggerPublisher publisher)
          Remove a publisher that has previously been added.
 void vdebug(java.lang.String message)
          A convenience method
 void verbose(java.lang.String message)
          A convenience method
 void vverbose(java.lang.String message)
          A convenience method
 void warn(java.lang.String message)
          A convenience method
 void warn(java.lang.String message, java.lang.Exception ex)
          A convenience method
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SILENT

public static final int SILENT
Used only by LoggerPublishers: indicates that no messages should be published. You should not publish messages at this priority.

See Also:
Constant Field Values

ERROR

public static final int ERROR
failure has occurred, typically fatal

See Also:
Constant Field Values

WARN

public static final int WARN
a recoverable failure has occurred, or something suspicious occured.

See Also:
Constant Field Values

OUTPUT

public static final int OUTPUT
the expected output of the program.

See Also:
Constant Field Values

VERBOSE

public static final int VERBOSE
occasional status messages

See Also:
Constant Field Values

VVERBOSE

public static final int VVERBOSE
more frequent status messages

See Also:
Constant Field Values

DEBUG

public static final int DEBUG
extensive debugging information

See Also:
Constant Field Values

VDEBUG

public static final int VDEBUG
ludicrous quantities of debug information

See Also:
Constant Field Values

consolePublisher

public static ConsoleLoggerPublisher consolePublisher

startTime

public static long startTime
Constructor Detail

Logger

public Logger(java.lang.String name)
Create a new logger with the specified name.


Logger

public Logger(java.lang.Object o)
Create a logger which will take its name as the class name of the argument.

Method Detail

levelToString

public static java.lang.String levelToString(int level)
Convert an integer value corresponding to a debug level into a human-readable string, e.g. "VERBOSE".

Parameters:
level - One of the static levels provided by this class.
Returns:
a human-readable string, e.g. "VERBOSE".

log

public void log(int level,
                java.lang.String message)
Log a message for this channel


log

public void log(int level,
                java.lang.String message,
                java.lang.Exception ex)
Log a message for this channel


error

public void error(java.lang.String message,
                  java.lang.Exception ex)
A convenience method


error

public void error(java.lang.String message)
A convenience method


warn

public void warn(java.lang.String message,
                 java.lang.Exception ex)
A convenience method


warn

public void warn(java.lang.String message)
A convenience method


output

public void output(java.lang.String message)
A convenience method


output

public void output(java.lang.String message,
                   java.lang.Exception ex)
A convenience method


verbose

public void verbose(java.lang.String message)
A convenience method


vverbose

public void vverbose(java.lang.String message)
A convenience method


debug

public void debug(java.lang.String message)
A convenience method


vdebug

public void vdebug(java.lang.String message)
A convenience method


addPublisher

public static void addPublisher(LoggerPublisher publisher)
Add a new publisher

Parameters:
publisher - a new LoggerPublisher which will be told about all events.

removePublisher

public static void removePublisher(LoggerPublisher publisher)
Remove a publisher that has previously been added.

Parameters:
publisher - The publisher to be removed.

log

public static void log(java.lang.String name,
                       int level,
                       java.lang.String message,
                       java.lang.Exception ex)
Produce a log message containing information about an exception that occured. Many of the convenience methods ultimately call this function. The convenience methods should typically be used for readability.


log

public static void log(java.lang.String name,
                       int level,
                       java.lang.String message)
The actual log method. All other log calls ultimately call this method which actually invokes the publishers.

Parameters:
name - The channel name
level - The log level
message - The message

main

public static void main(java.lang.String[] args)