Firefish 0.5.10

gov.lbl.dsd.p2pio.util
Class Logger

java.lang.Object
  extended bygov.lbl.dsd.p2pio.util.Logger
All Implemented Interfaces:
Log

public class Logger
extends Object
implements Log

A Log that delegates to an underlying child log and implements easy yet efficient logging of two object messages which are to be string-concatenated. This class avoids unnecessary string concatenation if the given log level is disabled. This is often the case, in particular for debug messages in Internet servers or similar. Recall that commons Log as well as log4j Logger and java.util.logging Logger only support logging of a single message (not two).

Here is a demonstration of the problem and solution. Using commons logging one would write code as follows:

 // snippet 1
 org.apache.commons.logging.Log log = ...
 Object message = ...
 log.debug("now handling input message = " + message);
 
If debugging is disabled the following snippet is sometimes MUCH more efficient:
 // snippet 2
 org.apache.commons.logging.Log log = ...
 Object message = ...
 if (log.isDebugEnabled) {
 log.debug("now handling input message = " + message);
 }
 
Using our own Logger class the following snippet 3 combines the convenience of snippet 1 and the efficiency of snippet 2:
 // snippet 3
 Logger log = ...
 // or: Logger log = new Logger(org.apache.commons.logging.Log)
 Object message = ...
 log.debug("now handling input msg = ", message);
 //or: log.debug("now handling input msg = ", message, someThrowable);
 }
 

Version:
$Revision: 1.4 $, $Date: 2004/01/30 01:18:02 $

Constructor Summary
Logger(Log childLog)
           
 
Method Summary
 void debug(Object message)
           
 void debug(Object message1, Object message2)
           
 void debug(Object message1, Object message2, Throwable t)
           
 void debug(Object message, Throwable t)
           
 void error(Object message)
           
 void error(Object message1, Object message2)
           
 void error(Object message1, Object message2, Throwable t)
           
 void error(Object message, Throwable t)
           
 void fatal(Object message)
           
 void fatal(Object message1, Object message2)
           
 void fatal(Object message1, Object message2, Throwable t)
           
 void fatal(Object message, Throwable t)
           
static Logger getLog(Class clazz)
          Convenience method to return a named logger, without the application having to care about factories.
static Logger getLog(String name)
          Convenience method to return a named logger, without the application having to care about factories.
 void info(Object message)
           
 void info(Object message1, Object message2)
           
 void info(Object message1, Object message2, Throwable t)
           
 void info(Object message, Throwable t)
           
 boolean isDebugEnabled()
           
 boolean isErrorEnabled()
           
 boolean isFatalEnabled()
           
 boolean isInfoEnabled()
           
 boolean isTraceEnabled()
           
 boolean isWarnEnabled()
           
 void trace(Object message)
           
 void trace(Object message1, Object message2)
           
 void trace(Object message1, Object message2, Throwable t)
           
 void trace(Object message, Throwable t)
           
 void warn(Object message)
           
 void warn(Object message1, Object message2)
           
 void warn(Object message1, Object message2, Throwable t)
           
 void warn(Object message, Throwable t)
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Logger

public Logger(Log childLog)
Method Detail

getLog

public static Logger getLog(Class clazz)
Convenience method to return a named logger, without the application having to care about factories.

Parameters:
clazz - Class for which a log name will be derived
Throws:
LogConfigurationException - if a suitable Log instance cannot be returned

getLog

public static Logger getLog(String name)
Convenience method to return a named logger, without the application having to care about factories.

Parameters:
name - Logical name of the Log instance to be returned (the meaning of this name is only known to the underlying logging implementation that is being wrapped)
Throws:
LogConfigurationException - if a suitable Log instance cannot be returned

trace

public void trace(Object message)
Specified by:
trace in interface Log

trace

public void trace(Object message,
                  Throwable t)
Specified by:
trace in interface Log

trace

public void trace(Object message1,
                  Object message2)

trace

public void trace(Object message1,
                  Object message2,
                  Throwable t)

debug

public void debug(Object message)
Specified by:
debug in interface Log

debug

public void debug(Object message,
                  Throwable t)
Specified by:
debug in interface Log

debug

public void debug(Object message1,
                  Object message2)

debug

public void debug(Object message1,
                  Object message2,
                  Throwable t)

info

public void info(Object message)
Specified by:
info in interface Log

info

public void info(Object message,
                 Throwable t)
Specified by:
info in interface Log

info

public void info(Object message1,
                 Object message2)

info

public void info(Object message1,
                 Object message2,
                 Throwable t)

warn

public void warn(Object message)
Specified by:
warn in interface Log

warn

public void warn(Object message,
                 Throwable t)
Specified by:
warn in interface Log

warn

public void warn(Object message1,
                 Object message2)

warn

public void warn(Object message1,
                 Object message2,
                 Throwable t)

error

public void error(Object message)
Specified by:
error in interface Log

error

public void error(Object message,
                  Throwable t)
Specified by:
error in interface Log

error

public void error(Object message1,
                  Object message2)

error

public void error(Object message1,
                  Object message2,
                  Throwable t)

fatal

public void fatal(Object message)
Specified by:
fatal in interface Log

fatal

public void fatal(Object message,
                  Throwable t)
Specified by:
fatal in interface Log

fatal

public void fatal(Object message1,
                  Object message2)

fatal

public void fatal(Object message1,
                  Object message2,
                  Throwable t)

isTraceEnabled

public final boolean isTraceEnabled()
Specified by:
isTraceEnabled in interface Log

isDebugEnabled

public final boolean isDebugEnabled()
Specified by:
isDebugEnabled in interface Log

isInfoEnabled

public final boolean isInfoEnabled()
Specified by:
isInfoEnabled in interface Log

isWarnEnabled

public final boolean isWarnEnabled()
Specified by:
isWarnEnabled in interface Log

isErrorEnabled

public final boolean isErrorEnabled()
Specified by:
isErrorEnabled in interface Log

isFatalEnabled

public final boolean isFatalEnabled()
Specified by:
isFatalEnabled in interface Log

Firefish 0.5.10

Jump to the Firefish Homepage