org.objectweb.cjdbc.common.log
Class Trace

java.lang.Object
  extended byorg.objectweb.cjdbc.common.log.Trace
Direct Known Subclasses:
StaticDisabledLogger, StaticNoDebugLogger

public class Trace
extends java.lang.Object

This a wrapper to the log4j logging system. We provide additional features to statically remove tracing.

Version:
1.0
Author:
Emmanuel Cecchet

Field Summary
private  org.apache.log4j.Logger log4jLogger
          Log4j logger instance.
 
Constructor Summary
protected Trace(org.apache.log4j.Logger log4jLogger)
          Creates a new Trace object from a given log4j Logger.
 
Method Summary
 void debug(java.lang.Object message)
          Logs a message object with the DEBUG Level.
 void debug(java.lang.Object message, java.lang.Throwable error)
          Logs a message object with the DEBUG Level including the stack trace of the Throwableerror passed as parameter.
 void error(java.lang.Object message)
          Logs a message object with the ERROR Level.
 void error(java.lang.Object message, java.lang.Throwable error)
          Logs a message object with the ERROR Level including the stack trace of the Throwableerror passed as parameter.
 void fatal(java.lang.Object message)
          Logs a message object with the FATAL Level.
 void fatal(java.lang.Object message, java.lang.Throwable error)
          Logs a message object with the FATAL Level including the stack trace of the Throwableerror passed as parameter.
static Trace getLogger(java.lang.String name)
          Retrieves a logger by its name.
 void info(java.lang.Object message)
          Logs a message object with the INFO Level.
 void info(java.lang.Object message, java.lang.Throwable error)
          Logs a message object with the INFO Level including the stack trace of the Throwableerror passed as parameter.
 boolean isDebugEnabled()
          Checks whether this category is enabled for the DEBUG Level.
 boolean isErrorEnabled()
          Checks whether this category is enabled for the INFO Level.
 boolean isFatalEnabled()
          Checks whether this category is enabled for the INFO Level.
 boolean isInfoEnabled()
          Checks whether this category is enabled for the INFO Level.
 boolean isWarnEnabled()
          Checks whether this category is enabled for the INFO Level.
 void warn(java.lang.Object message)
          Logs a message object with the WARN Level.
 void warn(java.lang.Object message, java.lang.Throwable error)
          Logs a message object with the WARN Level including the stack trace of the Throwableerror passed as parameter.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log4jLogger

private org.apache.log4j.Logger log4jLogger
Log4j logger instance.

Constructor Detail

Trace

protected Trace(org.apache.log4j.Logger log4jLogger)
Creates a new Trace object from a given log4j Logger.

Parameters:
log4jLogger - the log4j Logger
Method Detail

getLogger

public static Trace getLogger(java.lang.String name)
Retrieves a logger by its name.

Parameters:
name - logger name
Returns:
trace a Trace instance

debug

public void debug(java.lang.Object message)
Logs a message object with the DEBUG Level.

Parameters:
message - the message object to log

debug

public void debug(java.lang.Object message,
                  java.lang.Throwable error)
Logs a message object with the DEBUG Level including the stack trace of the Throwableerror passed as parameter.

Parameters:
message - the message object to log
error - the exception to log, including its stack trace

error

public void error(java.lang.Object message)
Logs a message object with the ERROR Level.

Parameters:
message - the message object to log

error

public void error(java.lang.Object message,
                  java.lang.Throwable error)
Logs a message object with the ERROR Level including the stack trace of the Throwableerror passed as parameter.

Parameters:
message - the message object to log.
error - the exception to log, including its stack trace.

fatal

public void fatal(java.lang.Object message)
Logs a message object with the FATAL Level.

Parameters:
message - the message object to log.

fatal

public void fatal(java.lang.Object message,
                  java.lang.Throwable error)
Logs a message object with the FATAL Level including the stack trace of the Throwableerror passed as parameter.

Parameters:
message - the message object to log.
error - the exception to log, including its stack trace.

info

public void info(java.lang.Object message)
Logs a message object with the INFO Level.

Parameters:
message - the message object to log.

info

public void info(java.lang.Object message,
                 java.lang.Throwable error)
Logs a message object with the INFO Level including the stack trace of the Throwableerror passed as parameter.

Parameters:
message - the message object to log.
error - the exception to log, including its stack trace.

warn

public void warn(java.lang.Object message)
Logs a message object with the WARN Level.

Parameters:
message - the message object to log.

warn

public void warn(java.lang.Object message,
                 java.lang.Throwable error)
Logs a message object with the WARN Level including the stack trace of the Throwableerror passed as parameter.

Parameters:
message - the message object to log.
error - the exception to log, including its stack trace.

isDebugEnabled

public boolean isDebugEnabled()
Checks whether this category is enabled for the DEBUG Level.

This function is intended to lessen the computational cost of disabled log debug statements.

For some cat Category object, when you write,

  cat.debug("This is entry number: " + i );
 

You incur the cost constructing the message, concatenatiion in this case, regardless of whether the message is logged or not.

If you are worried about speed, then you should write

  if(cat.isDebugEnabled()) { cat.debug("This is entry number: " + i ); }
 

This way you will not incur the cost of parameter construction if debugging is disabled for cat. On the other hand, if the cat is debug enabled, you will incur the cost of evaluating whether the category is debug enabled twice. Once in isDebugEnabled and once in the debug. This is an insignificant overhead since evaluating a category takes about 1%% of the time it takes to actually log.

Returns:
true if this category is debug enabled, false otherwise.

isInfoEnabled

public boolean isInfoEnabled()
Checks whether this category is enabled for the INFO Level. See also isDebugEnabled().

Returns:
true if this category is enabled for Level INFO, false otherwise.

isWarnEnabled

public boolean isWarnEnabled()
Checks whether this category is enabled for the INFO Level. See also isDebugEnabled().

Returns:
true if this category is enabled for INFO Level, false otherwise.

isErrorEnabled

public boolean isErrorEnabled()
Checks whether this category is enabled for the INFO Level. See also isDebugEnabled().

Returns:
true if this category is enabled for INFO Level, false otherwise.

isFatalEnabled

public boolean isFatalEnabled()
Checks whether this category is enabled for the INFO Level. See also isDebugEnabled().

Returns:
true if this category is enabled for INFO Level, false otherwise.


Copyright © 2002, 2005 - ObjectWeb Consortium - All Rights Reserved.