cage.core
Class Logger

java.lang.Object
  extended by cage.core.Logger

public class Logger
extends java.lang.Object

This simple logging system is modeled after the fuctionality of log4j but only includes the features needed for CAGE. A static logger named rootLogger can be access via getRootLogger. The static logger by default prints to System.out and is at ERROR level. By default, all loggers take the level and printing target from the root logger. In general, classes can simply keep a reference to the rootLogger and print to that, but instances of Logger can be created if you want to have different levels of reporting between classes or if you want to have one class print to a different stream than the root logger. The static message strings, debugMessage, infoMessage, and errorMessage are prepended to all logger output of the respective levels. The defaults can be replaced with custom strings via the setters.

Author:
Seth Marinello

Nested Class Summary
static class Logger.Level
          Constants for the Level of the logger.
 
Field Summary
static boolean guiMode
          If true, error level messages will be displayed in GUI Dialogs
 
Constructor Summary
Logger()
          Creates a default logger
Logger(Logger.Level level)
          Creates a logger which the specified level but default print stream.
Logger(java.io.PrintStream out)
          Creates a logger that uses the provided Printstream for output
Logger(java.io.PrintStream out, Logger.Level level)
          Creates a logger with a custom print stream and level
 
Method Summary
 void debug(java.lang.Object obj)
          Print a debug message
 void debug(java.lang.Object obj, java.lang.Throwable t)
          Print a debug message
 void error(java.lang.Object obj)
          Print a error message
 void error(java.lang.Object obj, java.lang.Throwable t)
          Print a error message
static java.lang.String getDebugMessage()
          Gets the message.
static java.lang.String getErrorMessage()
          Gets the message.
static int getIndent()
          Gets the indent amount for all loggers.
static java.lang.String getInfoMessage()
          Gets the message.
 Logger.Level getLevel()
          The level of output allowed
 java.io.PrintStream getOut()
          Returns the output stream
static Logger getRootLogger()
          Gets the static logger all loggers grow from.
 void info(java.lang.Object obj)
          Print a info message
 void info(java.lang.Object obj, java.lang.Throwable t)
          Print a info message
static void setDebugMessage(java.lang.String debugMessage)
          Sets the message.
static void setErrorMessage(java.lang.String errorMessage)
          Sets the message.
static void setIndent(int indent)
          Sets the indent amount in spaces.
static void setInfoMessage(java.lang.String infoMessage)
          Sets the message.
 void setLevel(Logger.Level level)
          Sets the output level
 void setOut(java.io.PrintStream out)
          Sets the stream the logger writes to
static void setRootLogger(Logger rootLogger)
          Allows replacement of the root logger
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

guiMode

public static boolean guiMode
If true, error level messages will be displayed in GUI Dialogs

Constructor Detail

Logger

public Logger()
Creates a default logger


Logger

public Logger(java.io.PrintStream out)
Creates a logger that uses the provided Printstream for output

Parameters:
out - Stream to write the log to.

Logger

public Logger(Logger.Level level)
Creates a logger which the specified level but default print stream.

Parameters:
level - Level to set the logger to.

Logger

public Logger(java.io.PrintStream out,
              Logger.Level level)
Creates a logger with a custom print stream and level

Parameters:
out - Stream to write the log to.
level - Level to set the logger to.
Method Detail

debug

public void debug(java.lang.Object obj)
Print a debug message

Parameters:
obj - Object to print

debug

public void debug(java.lang.Object obj,
                  java.lang.Throwable t)
Print a debug message

Parameters:
obj - Object to print
t - A throwable object, often the exception you are logging

info

public void info(java.lang.Object obj)
Print a info message

Parameters:
obj - Object to print

info

public void info(java.lang.Object obj,
                 java.lang.Throwable t)
Print a info message

Parameters:
obj - Object to print
t - A throwable object, often the exception you are logging

error

public void error(java.lang.Object obj)
Print a error message

Parameters:
obj - Object to print

error

public void error(java.lang.Object obj,
                  java.lang.Throwable t)
Print a error message

Parameters:
obj - Object to print
t - A throwable object, often the exception you are logging

getDebugMessage

public static java.lang.String getDebugMessage()
Gets the message.

Returns:
The message prepended to all debug messages.

setDebugMessage

public static void setDebugMessage(java.lang.String debugMessage)
Sets the message.

Parameters:
debugMessage - The message prepended to all debug messages.

getErrorMessage

public static java.lang.String getErrorMessage()
Gets the message.

Returns:
The message prepended to all error messages.

setErrorMessage

public static void setErrorMessage(java.lang.String errorMessage)
Sets the message.

Parameters:
errorMessage - The message prepended to all error messages.

getInfoMessage

public static java.lang.String getInfoMessage()
Gets the message.

Returns:
The message prepended to all debug messages.

setInfoMessage

public static void setInfoMessage(java.lang.String infoMessage)
Sets the message.

Parameters:
infoMessage - The message prepended to all info messages.

getLevel

public Logger.Level getLevel()
The level of output allowed

Returns:
the currentl level of the logger.

setLevel

public void setLevel(Logger.Level level)
Sets the output level

Parameters:
level - level to set this logger to

getOut

public java.io.PrintStream getOut()
Returns the output stream

Returns:
the PrintStream the logger prints to.

setOut

public void setOut(java.io.PrintStream out)
Sets the stream the logger writes to

Parameters:
out - The stream to write to.

getIndent

public static int getIndent()
Gets the indent amount for all loggers.

Returns:
indent amount in spaces

setIndent

public static void setIndent(int indent)
Sets the indent amount in spaces.

Parameters:
indent - number of spaces to indent

getRootLogger

public static Logger getRootLogger()
Gets the static logger all loggers grow from.

Returns:
the root logger

setRootLogger

public static void setRootLogger(Logger rootLogger)
Allows replacement of the root logger

Parameters:
rootLogger - logger to replace the root logger.