uk.org.ogsadai.common.msgs
Class DAILogger

java.lang.Object
  |
  +--uk.org.ogsadai.common.msgs.DAILogger

public class DAILogger
extends java.lang.Object

Class responsible for logging.

Handles internationalization of logging messages and forces developers to internationalise messages that are logged at any level higher than DEBUG.

Author:
The OGSA-DAI Project Team

Field Summary
private static java.lang.String COPYRIGHT_NOTICE
          Copyright statement
private  boolean debugEnabled
          Is the DEBUG level of logging enabled?
private  java.lang.Class mClass
          Class for which logging is being managed
private  org.apache.log4j.Logger mLogger
          Log4J Logger used for logging
 
Constructor Summary
private DAILogger(java.lang.Class theClass)
          Private constructor.
 
Method Summary
private  java.lang.String addIDToMessage(DAIUniqueID id, java.lang.String message)
          Adds a unique ID to a message string.
 void debug(DAIUniqueID id, java.lang.String message)
          Logs a debug message with the given ID.
 void debug(java.lang.String message)
          Logs a debug message.
 void error(java.lang.Throwable exception)
          Logs a set of internationalized error messages associated with the given exception and all its child exceptions.
 void error(java.lang.Throwable exception, boolean stackTrace)
          Logs a set of internationalized error messages associated with the given exception and all its child exceptions.
private  void errorExceptionAndChildren(java.lang.Throwable e, boolean stackTrace)
          Logs as a warning the given exception and all its children.
 void fatal(java.lang.Throwable exception)
          Logs a set of internationalized fatal messages associated with the given exception and all its child exceptions.
 void fatal(java.lang.Throwable exception, boolean stackTrace)
          Logs a set of internationalized fatal messages associated with the given exception and all its child exceptions.
private  void fatalExceptionAndChildren(java.lang.Throwable e, boolean stackTrace)
          Logs as a warning the given exception and all its children.
private  java.lang.String getLocalizedMessage(DAIUniqueID id, MessageID messageID, java.lang.Object[] parameters)
          Gets the internationalized message from the message loader and appends the unique ID to it.
private  java.lang.String getLocalizedMessage(MessageID messageID, java.lang.Object[] parameters)
          Gets the internationalized message from the message loader.
static DAILogger getLogger(java.lang.Class theClass)
          Factory method to get a logger for the specified class.
private  java.lang.String getStackTrace(java.lang.Throwable ex)
          Get an exception stack trace as a string.
 void info(MessageID messageID)
          Logs the internationalized information message associated with the given message ID.
 void info(MessageID messageID, java.lang.Object parameter)
          Logs the internationalized information message associated with the given message ID using the given parameters.
 void info(MessageID messageID, java.lang.Object[] parameters)
          Logs the internationalized information message associated with the given message ID using the given parameters.
 boolean isDebugEnabled()
          Gets whether or not debug logging in enabled.
 boolean isInfoEnabled()
          Gets whether or not informational logging in enabled.
private  void logStackTraceDebug(java.lang.Throwable e)
          Log an exception stack trace.
private  void logStackTraceError(java.lang.Throwable e)
          Log an exception stack trace.
private  void logStackTraceFatal(java.lang.Throwable e)
          Log an exception stack trace.
private  void logStackTraceWarn(java.lang.Throwable e)
          Log an exception stack trace.
(package private)  void warn(ErrorID errorID, java.lang.Object[] parameters)
          Logs a bare bones warning message associated with the given error ID using the given parameters.
 void warn(java.lang.Throwable exception)
          Logs a set of internationalized warning messages associated with the given exception and all its child exceptions.
 void warn(java.lang.Throwable exception, boolean stackTrace)
          Logs a set of internationalized warning messages associated with the given exception and all its child exceptions.
private  void warnExceptionAndChildren(java.lang.Throwable e, boolean stackTrace)
          Logs as a warning the given exception and all its children.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

COPYRIGHT_NOTICE

private static final java.lang.String COPYRIGHT_NOTICE
Copyright statement

See Also:
Constant Field Values

mClass

private java.lang.Class mClass
Class for which logging is being managed


mLogger

private org.apache.log4j.Logger mLogger
Log4J Logger used for logging


debugEnabled

private boolean debugEnabled
Is the DEBUG level of logging enabled?

Constructor Detail

DAILogger

private DAILogger(java.lang.Class theClass)
Private constructor. To create a new logger use the static factory method.

Parameters:
theClass - The class being logged.
Method Detail

getLogger

public static DAILogger getLogger(java.lang.Class theClass)
Factory method to get a logger for the specified class.

Parameters:
theClass - The class being logged.
Returns:
a new logger.

debug

public void debug(java.lang.String message)
Logs a debug message. Debug messages are not internationalized.

Parameters:
message - The debug message to log.

debug

public void debug(DAIUniqueID id,
                  java.lang.String message)
Logs a debug message with the given ID. Debug message are not internationalized.

Parameters:
id - ID to log with message.
message - The debug message to log.

isDebugEnabled

public boolean isDebugEnabled()
Gets whether or not debug logging in enabled.

Returns:
true if logging is enabled, false otherwise.

info

public void info(MessageID messageID)
Logs the internationalized information message associated with the given message ID.

Parameters:
messageID - Message ID identifying message to log.

info

public void info(MessageID messageID,
                 java.lang.Object parameter)
Logs the internationalized information message associated with the given message ID using the given parameters.

Parameters:
messageID - Message ID identifying message to log.
parameter - Parameter associated with message. The toString() method will be applied to the parameter to obtain the string inserted into the message log.

info

public void info(MessageID messageID,
                 java.lang.Object[] parameters)
Logs the internationalized information message associated with the given message ID using the given parameters.

Parameters:
messageID - Message ID identifying message to log.
parameters - Parameters associated with message. The toString() method will be applied to all parameters to obtain the strings inserted into the message log.

isInfoEnabled

public boolean isInfoEnabled()
Gets whether or not informational logging in enabled.

Returns:
true if logging is enabled, false otherwise.

warn

public void warn(java.lang.Throwable exception)
Logs a set of internationalized warning messages associated with the given exception and all its child exceptions.

Parameters:
exception - Exception containing messages to be logged.

warn

public void warn(java.lang.Throwable exception,
                 boolean stackTrace)
Logs a set of internationalized warning messages associated with the given exception and all its child exceptions.

Parameters:
exception - Exception containing messages to be logged.
stackTrace - Log the stack trace?

error

public void error(java.lang.Throwable exception)
Logs a set of internationalized error messages associated with the given exception and all its child exceptions.

Parameters:
exception - Exception containing messages to be logged.

error

public void error(java.lang.Throwable exception,
                  boolean stackTrace)
Logs a set of internationalized error messages associated with the given exception and all its child exceptions.

Parameters:
exception - Exception containing messages to be logged.
stackTrace - Log the stack trace?

warn

void warn(ErrorID errorID,
          java.lang.Object[] parameters)
Logs a bare bones warning message associated with the given error ID using the given parameters. No internationalization is attempted. This is package-level as it is intended for use by MessageLoader if it cannot find a message bundle.

Parameters:
errorID - Error ID identifying message to log.
parameters - Parameters associated with message. The toString() method will be applied to all parameters to obtain the strings inserted into the message log.

fatal

public void fatal(java.lang.Throwable exception)
Logs a set of internationalized fatal messages associated with the given exception and all its child exceptions.

Parameters:
exception - Exception containing messages to be logged.

fatal

public void fatal(java.lang.Throwable exception,
                  boolean stackTrace)
Logs a set of internationalized fatal messages associated with the given exception and all its child exceptions.

Parameters:
exception - Exception containing messages to be logged.
stackTrace - Log the stack trace?

warnExceptionAndChildren

private void warnExceptionAndChildren(java.lang.Throwable e,
                                      boolean stackTrace)
Logs as a warning the given exception and all its children. All the log entried will be associated with the same given ID so that they can be identified as a batch.

Each exception and its children will be logged with messages from any exception implementing uk.org.ogsadai.exception.DAIExceptionInformation being internationalized.

Parameters:
e - Exception to log.
stackTrace - Log the stack trace?

errorExceptionAndChildren

private void errorExceptionAndChildren(java.lang.Throwable e,
                                       boolean stackTrace)
Logs as a warning the given exception and all its children. All the log entried will be associated with the same given ID so that they can be identified as a batch.

Each exception and its children will be logged with messages from any exception implementing uk.org.ogsadai.exception.DAIExceptionInformation being internationalized.

Parameters:
e - Exception to log
stackTrace - Log the stack trace?

fatalExceptionAndChildren

private void fatalExceptionAndChildren(java.lang.Throwable e,
                                       boolean stackTrace)
Logs as a warning the given exception and all its children. All the log entried will be associated with the same given ID so that they can be identified as a batch.

Each exception and its children will be logged with messages from any exception implementing uk.org.ogsadai.exception.DAIExceptionInformation being internationalized.

Parameters:
e - Exception to log
stackTrace - Log the stack trace?

getLocalizedMessage

private java.lang.String getLocalizedMessage(MessageID messageID,
                                             java.lang.Object[] parameters)
Gets the internationalized message from the message loader.

Parameters:
messageID - ID of message.
parameters - Parameters to insert into message. The toString() method will be applied to all parameters to obtain the strings inserted into the message log.
Returns:
the internationalized message.

getLocalizedMessage

private java.lang.String getLocalizedMessage(DAIUniqueID id,
                                             MessageID messageID,
                                             java.lang.Object[] parameters)
Gets the internationalized message from the message loader and appends the unique ID to it.

Parameters:
id - Unique ID to associate with this message.
messageID - ID of message.
parameters - Parameters to insert into message. The toString() method will be applied to all parameters to obtain the strings inserted into the message log.
Returns:
the internationalized message.

addIDToMessage

private java.lang.String addIDToMessage(DAIUniqueID id,
                                        java.lang.String message)
Adds a unique ID to a message string.

Parameters:
id - Unique ID associated with message
message - The message.
Returns:
the unique ID prepended to the message in the form #id# message.

getStackTrace

private java.lang.String getStackTrace(java.lang.Throwable ex)
Get an exception stack trace as a string.

Parameters:
ex - Exception.
Returns:
string.

logStackTraceDebug

private void logStackTraceDebug(java.lang.Throwable e)
Log an exception stack trace.

Parameters:
e - Exception.

logStackTraceWarn

private void logStackTraceWarn(java.lang.Throwable e)
Log an exception stack trace.

Parameters:
e - Exception.

logStackTraceError

private void logStackTraceError(java.lang.Throwable e)
Log an exception stack trace.

Parameters:
e - Exception.

logStackTraceFatal

private void logStackTraceFatal(java.lang.Throwable e)
Log an exception stack trace.

Parameters:
e - Exception.