com.mcdermottroe.exemplar.ui
Class Log

java.lang.Object
  extended by com.mcdermottroe.exemplar.ui.Log

public final class Log
extends Object

A single point of entry for all logging within the program.

To set up the program for logging (this should be done within a UI):

// Create a Handler
Handler handler = new MyCustomHandler();

// Register the Handler with this class
Log.registerHandler(Handler handler);
                

To publish log messages, simply pick the level of message you wish to send and use the corresponding method. For example, to publish a warning:

Log.warning("The foo subsystem is almost out of memory!");
                

Conversion table between log levels in this class and the Levels in the java.util.logging package.

Method in this class Log Level produced
error(CharSequence...) Level.SEVERE
warning(CharSequence...) Level.WARNING
info(CharSequence...) Level.INFO
debug(CharSequence...) Level.FINE

Since:
0.2

Field Summary
private  Logger logger
          The underlying Logger through which all logging will flow.
private static Log logInst
          The singleton instance for this class.
 
Constructor Summary
private Log()
          Constructor for the singleton object.
 
Method Summary
private static StackTraceElement caller()
          Find the method and class from where the "outer" method of this class was called.
static void clearHandlers()
          Clear all Handlers from the underlying logger.
static void debug(CharSequence... messages)
          Log a debugging message.
static void debug(Throwable cause, CharSequence... messages)
          Log a debug message about an exception.
private static void doLog(CharSequence[] m, Throwable t, Level l)
          Convenient form for doLog(LogRecord).
private static void doLog(LogRecord logRecord)
          Actual work of logging is done here.
static void error(CharSequence... messages)
          Log an error message.
static void error(Throwable cause, CharSequence... messages)
          Log an error message with the exception that caused the error.
static LogLevel getLevel()
          Get the current LogLevel of the underlying Logger.
private  Logger getLogger()
          Get the underlying Logger.
static void info(CharSequence... messages)
          Log an informational message about an exception which occurred and has been either successfully dealt with or ignored.
static void registerHandler(Handler handler)
          Register a Handler as the destination for all log messages.
static void setLevel(LogLevel level)
          Set the LogLevel of logging to something other than the default.
static void warning(CharSequence... messages)
          Log a warning message.
static void warning(Throwable cause, CharSequence... messages)
          Log a warning message with the exception that caused the problem.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logInst

private static final Log logInst
The singleton instance for this class.


logger

private final Logger logger
The underlying Logger through which all logging will flow.

Constructor Detail

Log

private Log()
Constructor for the singleton object.

Method Detail

getLogger

private Logger getLogger()
Get the underlying Logger.

Returns:
The underlying Logger.

registerHandler

public static void registerHandler(Handler handler)
Register a Handler as the destination for all log messages.

Parameters:
handler - The Handler which all log messages should be passed to.

clearHandlers

public static void clearHandlers()
Clear all Handlers from the underlying logger.


getLevel

public static LogLevel getLevel()
Get the current LogLevel of the underlying Logger.

Returns:
THe current LogLevel.

setLevel

public static void setLevel(LogLevel level)
Set the LogLevel of logging to something other than the default.

Parameters:
level - The lowest LogLevel of message which should be logged.

error

public static void error(CharSequence... messages)
Log an error message. These are typically un-ignorable or fatal messages.

Parameters:
messages - The error message to log.

error

public static void error(Throwable cause,
                         CharSequence... messages)
Log an error message with the exception that caused the error. These are typically un-ignorable or fatal messages.

Parameters:
messages - The error message to log.
cause - The Exception that caused the error condition.

warning

public static void warning(CharSequence... messages)
Log a warning message. These are typically important but non-fatal messages about exceptional circumstances.

Parameters:
messages - The warning message to log.

warning

public static void warning(Throwable cause,
                           CharSequence... messages)
Log a warning message with the exception that caused the problem. These are typically important but non-fatal messages about exceptional circumstances.

Parameters:
messages - The warning message to log.
cause - The Exception that caused the problem.

info

public static void info(CharSequence... messages)
Log an informational message about an exception which occurred and has been either successfully dealt with or ignored.

Parameters:
messages - The informational message to log.

debug

public static void debug(CharSequence... messages)
Log a debugging message. Debug messages can be used for anything, but will no be visible unless debugging is turned on.

Parameters:
messages - The debug message to log.

debug

public static void debug(Throwable cause,
                         CharSequence... messages)
Log a debug message about an exception.

Parameters:
messages - The debug message to log.
cause - The Exception which caused the problem.

doLog

private static void doLog(CharSequence[] m,
                          Throwable t,
                          Level l)
Convenient form for doLog(LogRecord).

Parameters:
m - The message to log.
t - If the message is being logged in response to an Exception, then the exception may be passed here.
l - The Level at which the message is to be logged.

doLog

private static void doLog(LogRecord logRecord)
Actual work of logging is done here.

Parameters:
logRecord - The LogRecord to log.

caller

private static StackTraceElement caller()
Find the method and class from where the "outer" method of this class was called.

Returns:
The name of the class from which the calling method has called from.