org.objectweb.easybeans.log
Class JDKLogger

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

public class JDKLogger
extends java.lang.Object
implements JLog, java.io.Serializable

Logger with I18n and infinite arguments.

Author:
Florent Benoit
See Also:
Serialized Form

Field Summary
private static boolean handlerSet
          Handler already set.
private  I18n i18n
          I18n object.
private  java.util.logging.Logger logger
          Logger object (transient).
private  java.lang.String name
          Name of this logger.
private static long serialVersionUID
          Id for serializable class.
static java.lang.String SET_HANDLER
          Property to disable the set of our own handler.
 
Constructor Summary
JDKLogger(java.lang.Class clazz, I18n i18n)
          Creates a new 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.
 java.util.logging.Logger getLogger()
           
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?
private  void log(java.util.logging.Level level, java.lang.String msg, java.lang.Throwable t)
          Log the given message with the given throwable (if any).
private  void replaceConsoleHandlerInParentHandlers(java.util.logging.Logger logger)
          Replace the console handler by our handler.
 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

name

private java.lang.String name
Name of this logger.


logger

private transient java.util.logging.Logger logger
Logger object (transient).


i18n

private I18n i18n
I18n object.


handlerSet

private static boolean handlerSet
Handler already set.


SET_HANDLER

public static final java.lang.String SET_HANDLER
Property to disable the set of our own handler.

See Also:
Constant Field Values
Constructor Detail

JDKLogger

public JDKLogger(java.lang.Class clazz,
                 I18n i18n)
Creates a new logger.

Parameters:
clazz - the class that requires a logger.
i18n - the internationalization object to use, if any.
Method Detail

log

private void log(java.util.logging.Level level,
                 java.lang.String msg,
                 java.lang.Throwable t)
Log the given message with the given throwable (if any).

Parameters:
level - the level of the message (to log)
msg - the content of the message
t - the throwable (if any)

replaceConsoleHandlerInParentHandlers

private void replaceConsoleHandlerInParentHandlers(java.util.logging.Logger logger)
Replace the console handler by our handler.

Parameters:
logger - the given logger to analyze.

getLogger

public java.util.logging.Logger getLogger()
Returns:
JDK logger

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

getI18n

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

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

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.

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.

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.

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.

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.

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