org.objectweb.easybeans.log
Class CommonsLoggerImpl

java.lang.Object
  extended by org.objectweb.easybeans.log.CommonsLoggerImpl
All Implemented Interfaces:
java.io.Serializable, JLog

public class CommonsLoggerImpl
extends java.lang.Object
implements JLog

Wrapping around a commons logger allowing to use internationalization and MessageFormat API.

Author:
Florent Benoit
See Also:
Serialized Form

Field Summary
private  I18n i18n
          Instance of I18n.
private static long serialVersionUID
          Id for serializable class.
private  org.apache.commons.logging.Log wrapped
          Wrapped commons logging logger.
 
Constructor Summary
CommonsLoggerImpl(org.apache.commons.logging.Log wrapped, I18n i18n)
          Build a new logger with the wrapped logger.
 
Method Summary
 void debug(java.lang.Object message, java.lang.Object... args)
           Log a message with debug log level.
 void error(java.lang.Object message, java.lang.Object... args)
           Log a message with error log level.
 void fatal(java.lang.Object message, java.lang.Object... args)
           Log a message with fatal log level.
 I18n getI18n()
          Gets the i18n object associated to this logger.
private  java.lang.String getMessage(java.lang.Object message, java.lang.Object... args)
          Gets a string message build with the given args.
*
private  java.lang.Throwable getThrowable(java.lang.Object... args)
          Try to find a Throwable object in the array of object args.
 void info(java.lang.Object message, java.lang.Object... args)
           Log a message with info log level.
 boolean isDebugEnabled()
           Is debug logging currently enabled?
 boolean isErrorEnabled()
           Is error logging currently enabled?
 boolean isFatalEnabled()
           Is fatal logging currently enabled?
 boolean isInfoEnabled()
           Is info logging currently enabled?
 boolean isTraceEnabled()
           Is trace logging currently enabled?
 boolean isWarnEnabled()
           Is warn logging currently enabled?
 void trace(java.lang.Object message)
           Log a message with trace log level.
 void trace(java.lang.Object message, java.lang.Object... args)
           Log a message with trace log level.
 void warn(java.lang.Object message, java.lang.Object... args)
           Log a message with warn log level.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

serialVersionUID

private static final long serialVersionUID
Id for serializable class.

See Also:
Constant Field Values

wrapped

private org.apache.commons.logging.Log wrapped
Wrapped commons logging logger.


i18n

private I18n i18n
Instance of I18n.

Constructor Detail

CommonsLoggerImpl

public CommonsLoggerImpl(org.apache.commons.logging.Log wrapped,
                         I18n i18n)
Build a new logger with the wrapped logger.

Parameters:
wrapped - the delegate logger.
i18n - the internationalization object to use, if any.
Method Detail

isDebugEnabled

public boolean isDebugEnabled()

Is debug logging currently enabled?

Call this method to prevent having to perform expensive operations (for example, String concatenation) when the log level is more than debug.

Specified by:
isDebugEnabled in interface JLog
Returns:
true if it is enabled, else false

isErrorEnabled

public boolean isErrorEnabled()

Is error logging currently enabled?

Call this method to prevent having to perform expensive operations (for example, String concatenation) when the log level is more than error.

Specified by:
isErrorEnabled in interface JLog
Returns:
true if it is enabled, else false

isFatalEnabled

public boolean isFatalEnabled()

Is fatal logging currently enabled?

Call this method to prevent having to perform expensive operations (for example, String concatenation) when the log level is more than fatal.

Specified by:
isFatalEnabled in interface JLog
Returns:
true if it is enabled, else false

isInfoEnabled

public boolean isInfoEnabled()

Is info logging currently enabled?

Call this method to prevent having to perform expensive operations (for example, String concatenation) when the log level is more than info.

Specified by:
isInfoEnabled in interface JLog
Returns:
true if it is enabled, else false

isTraceEnabled

public boolean isTraceEnabled()

Is trace logging currently enabled?

Call this method to prevent having to perform expensive operations (for example, String concatenation) when the log level is more than trace.

Specified by:
isTraceEnabled in interface JLog
Returns:
true if it is enabled, else false

isWarnEnabled

public boolean isWarnEnabled()

Is warn logging currently enabled?

Call this method to prevent having to perform expensive operations (for example, String concatenation) when the log level is more than warn.

Specified by:
isWarnEnabled in interface JLog
Returns:
true if it is enabled, else false

trace

public void trace(java.lang.Object message)

Log a message with trace log level.

Parameters:
message - log this message

trace

public void trace(java.lang.Object message,
                  java.lang.Object... args)

Log a message with trace log level.

Specified by:
trace in interface JLog
Parameters:
message - - This could be
  • an entry of an I18n repository
  • a preformated message given to MessageFormat class
  • or a simple object on which toString() method will be called
args - could be empty or contains the object for the formatter (I18n case). To log an exception, the exception must be the last argument.

debug

public void debug(java.lang.Object message,
                  java.lang.Object... args)

Log a message with debug log level.

Specified by:
debug in interface JLog
Parameters:
message - - This could be
  • an entry of an I18n repository
  • a preformated message given to MessageFormat class
  • or a simple object on which toString() method will be called
args - could be empty or contains the object for the formatter (I18n case). To log an exception, the exception must be the last argument.

info

public void info(java.lang.Object message,
                 java.lang.Object... args)

Log a message with info log level.

Specified by:
info in interface JLog
Parameters:
message - - This could be
  • an entry of an I18n repository
  • a preformated message given to MessageFormat class
  • or a simple object on which toString() method will be called
args - could be empty or contains the object for the formatter (I18n case). To log an exception, the exception must be the last argument.

warn

public void warn(java.lang.Object message,
                 java.lang.Object... args)

Log a message with warn log level.

Specified by:
warn in interface JLog
Parameters:
message - - This could be
  • an entry of an I18n repository
  • a preformated message given to MessageFormat class
  • or a simple object on which toString() method will be called
args - could be empty or contains the object for the formatter (I18n case). To log an exception, the exception must be the last argument.

error

public void error(java.lang.Object message,
                  java.lang.Object... args)

Log a message with error log level.

Specified by:
error in interface JLog
Parameters:
message - - This could be
  • an entry of an I18n repository
  • a preformated message given to MessageFormat class
  • or a simple object on which toString() method will be called
args - could be empty or contains the object for the formatter (I18n case). To log an exception, the exception must be the last argument.

fatal

public void fatal(java.lang.Object message,
                  java.lang.Object... args)

Log a message with fatal log level.

Specified by:
fatal in interface JLog
Parameters:
message - - This could be
  • an entry of an I18n repository
  • a preformated message given to MessageFormat class
  • or a simple object on which toString() method will be called
args - could be empty or contains the object for the formatter (I18n case). To log an exception, the exception must be the last argument.

getI18n

public I18n getI18n()
Gets the i18n object associated to this logger.

Specified by:
getI18n in interface JLog
Returns:
i18n object.

getMessage

private java.lang.String getMessage(java.lang.Object message,
                                    java.lang.Object... args)
Gets a string message build with the given args.
*

Parameters:
message - If the message is an i18n entry, this entry will be used to format the message.
Else, the arguments will be used as string formatter
args - given args use by the formatter
Returns:
a string representation of the given message.

getThrowable

private java.lang.Throwable getThrowable(java.lang.Object... args)
Try to find a Throwable object in the array of object args. The throwable should be the last parameter.

Parameters:
args - array of objects on which we need to find the Throwable
Returns:
a throwable object if last index if a Throwable or null