org.apache.log4j.spi
Class NOPLogger

java.lang.Object
  extended by org.apache.log4j.Category
      extended by org.apache.log4j.Logger
          extended by org.apache.log4j.spi.NOPLogger
All Implemented Interfaces:
AppenderAttachable

public final class NOPLogger
extends Logger

No-operation implementation of Logger used by NOPLoggerRepository.

Since:
1.2.15

Field Summary
 
Fields inherited from class org.apache.log4j.Category
additive, level, name, parent, repository, resourceBundle
 
Constructor Summary
NOPLogger(NOPLoggerRepository repo, String name)
          Create instance of Logger.
 
Method Summary
 void addAppender(Appender newAppender)
          Add newAppender to the list of appenders of this Category instance.
 void assertLog(boolean assertion, String msg)
          If assertion parameter is false, then logs msg as an error statement.
 void callAppenders(LoggingEvent event)
          Call the appenders in the hierrachy starting at this.
 void debug(Object message)
          Log a message object with the DEBUG level.
 void debug(Object message, Throwable t)
          Log a message object with the DEBUG level including the stack trace of the Throwable t passed as parameter.
 void error(Object message)
          Log a message object with the ERROR Level.
 void error(Object message, Throwable t)
          Log a message object with the ERROR level including the stack trace of the Throwable t passed as parameter.
 void fatal(Object message)
          Log a message object with the FATAL Level.
 void fatal(Object message, Throwable t)
          Log a message object with the FATAL level including the stack trace of the Throwable t passed as parameter.
 Enumeration getAllAppenders()
          Get the appenders contained in this category as an Enumeration.
 Appender getAppender(String name)
          Look for the appender named as name.
 Priority getChainedPriority()
          
 Level getEffectiveLevel()
          Starting from this category, search the category hierarchy for a non-null level and return it.
 ResourceBundle getResourceBundle()
          Return the inherited ResourceBundle for this category.
 void info(Object message)
          Log a message object with the INFO Level.
 void info(Object message, Throwable t)
          Log a message object with the INFO level including the stack trace of the Throwable t passed as parameter.
 boolean isAttached(Appender appender)
          Is the appender passed as parameter attached to this category?
 boolean isDebugEnabled()
          Check whether this category is enabled for the DEBUG Level.
 boolean isEnabledFor(Priority level)
          Check whether this category is enabled for a given Level passed as parameter.
 boolean isInfoEnabled()
          Check whether this category is enabled for the info Level.
 boolean isTraceEnabled()
          Check whether this category is enabled for the TRACE Level.
 void l7dlog(Priority priority, String key, Object[] params, Throwable t)
          Log a localized and parameterized message.
 void l7dlog(Priority priority, String key, Throwable t)
          Log a localized message.
 void log(Priority priority, Object message)
          This generic form is intended to be used by wrappers.
 void log(Priority priority, Object message, Throwable t)
          This generic form is intended to be used by wrappers.
 void log(String callerFQCN, Priority level, Object message, Throwable t)
          This is the most generic printing method.
 void removeAllAppenders()
          Remove all previously added appenders from this Category instance.
 void removeAppender(Appender appender)
          Remove the appender passed as parameter form the list of appenders.
 void removeAppender(String name)
          Remove the appender with the name passed as parameter form the list of appenders.
 void setLevel(Level level)
          Set the level of this Category.
 void setPriority(Priority priority)
          Set the level of this Category.
 void setResourceBundle(ResourceBundle bundle)
          Set the resource bundle to be used with localized logging methods Category.l7dlog(Priority,String,Throwable) and Category.l7dlog(Priority,String,Object[],Throwable).
 void trace(Object message)
          Log a message object with the TRACE level.
 void trace(Object message, Throwable t)
          Log a message object with the TRACE level including the stack trace of the Throwablet passed as parameter.
 void warn(Object message)
          Log a message object with the WARN Level.
 void warn(Object message, Throwable t)
          Log a message with the WARN level including the stack trace of the Throwable t passed as parameter.
 
Methods inherited from class org.apache.log4j.Logger
getLogger, getLogger, getLogger, getRootLogger
 
Methods inherited from class org.apache.log4j.Category
exists, forcedLog, getAdditivity, getCurrentCategories, getDefaultHierarchy, getHierarchy, getInstance, getInstance, getLevel, getLoggerRepository, getName, getParent, getPriority, getResourceBundleString, getRoot, setAdditivity, shutdown
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

NOPLogger

public NOPLogger(NOPLoggerRepository repo,
                 String name)
Create instance of Logger.

Parameters:
repo - repository, may not be null.
name - name, may not be null, use "root" for root logger.
Method Detail

addAppender

public void addAppender(Appender newAppender)
Add newAppender to the list of appenders of this Category instance.

If newAppender is already in the list of appenders, then it won't be added again.

Specified by:
addAppender in interface AppenderAttachable
Overrides:
addAppender in class Category

assertLog

public void assertLog(boolean assertion,
                      String msg)
If assertion parameter is false, then logs msg as an error statement.

The assert method has been renamed to assertLog because assert is a language reserved word in JDK 1.4.

Overrides:
assertLog in class Category
msg - The message to print if assertion is false.

callAppenders

public void callAppenders(LoggingEvent event)
Call the appenders in the hierrachy starting at this. If no appenders could be found, emit a warning.

This method calls all the appenders inherited from the hierarchy circumventing any evaluation of whether to log or not to log the particular log request.

Overrides:
callAppenders in class Category
Parameters:
event - the event to log.

debug

public void debug(Object message)
Log a message object with the DEBUG level.

This method first checks if this category is DEBUG enabled by comparing the level of this category with the DEBUG level. If this category is DEBUG enabled, then it converts the message object (passed as parameter) to a string by invoking the appropriate ObjectRenderer. It then proceeds to call all the registered appenders in this category and also higher in the hierarchy depending on the value of the additivity flag.

WARNING Note that passing a Throwable to this method will print the name of the Throwable but no stack trace. To print a stack trace use the Category.debug(Object, Throwable) form instead.

Overrides:
debug in class Category
Parameters:
message - the message object to log.

debug

public void debug(Object message,
                  Throwable t)
Log a message object with the DEBUG level including the stack trace of the Throwable t passed as parameter.

See Category.debug(Object) form for more detailed information.

Overrides:
debug in class Category
Parameters:
message - the message object to log.
t - the exception to log, including its stack trace.

error

public void error(Object message)
Log a message object with the ERROR Level.

This method first checks if this category is ERROR enabled by comparing the level of this category with ERROR Level. If this category is ERROR enabled, then it converts the message object passed as parameter to a string by invoking the appropriate ObjectRenderer. It proceeds to call all the registered appenders in this category and also higher in the hierarchy depending on the value of the additivity flag.

WARNING Note that passing a Throwable to this method will print the name of the Throwable but no stack trace. To print a stack trace use the Category.error(Object, Throwable) form instead.

Overrides:
error in class Category
Parameters:
message - the message object to log

error

public void error(Object message,
                  Throwable t)
Log a message object with the ERROR level including the stack trace of the Throwable t passed as parameter.

See Category.error(Object) form for more detailed information.

Overrides:
error in class Category
Parameters:
message - the message object to log.
t - the exception to log, including its stack trace.

fatal

public void fatal(Object message)
Log a message object with the FATAL Level.

This method first checks if this category is FATAL enabled by comparing the level of this category with FATAL Level. If the category is FATAL enabled, then it converts the message object passed as parameter to a string by invoking the appropriate ObjectRenderer. It proceeds to call all the registered appenders in this category and also higher in the hierarchy depending on the value of the additivity flag.

WARNING Note that passing a Throwable to this method will print the name of the Throwable but no stack trace. To print a stack trace use the Category.fatal(Object, Throwable) form instead.

Overrides:
fatal in class Category
Parameters:
message - the message object to log

fatal

public void fatal(Object message,
                  Throwable t)
Log a message object with the FATAL level including the stack trace of the Throwable t passed as parameter.

See Category.fatal(Object) for more detailed information.

Overrides:
fatal in class Category
Parameters:
message - the message object to log.
t - the exception to log, including its stack trace.

getAllAppenders

public Enumeration getAllAppenders()
Get the appenders contained in this category as an Enumeration. If no appenders can be found, then a NullEnumeration is returned.

Specified by:
getAllAppenders in interface AppenderAttachable
Overrides:
getAllAppenders in class Category
Returns:
Enumeration An enumeration of the appenders in this category.

getAppender

public Appender getAppender(String name)
Look for the appender named as name.

Return the appender with that name if in the list. Return null otherwise.

Specified by:
getAppender in interface AppenderAttachable
Overrides:
getAppender in class Category

getEffectiveLevel

public Level getEffectiveLevel()
Starting from this category, search the category hierarchy for a non-null level and return it. Otherwise, return the level of the root category.

The Category class is designed so that this method executes as quickly as possible.

Overrides:
getEffectiveLevel in class Category

getChainedPriority

public Priority getChainedPriority()

Overrides:
getChainedPriority in class Category

getResourceBundle

public ResourceBundle getResourceBundle()
Return the inherited ResourceBundle for this category.

This method walks the hierarchy to find the appropriate resource bundle. It will return the resource bundle attached to the closest ancestor of this category, much like the way priorities are searched. In case there is no bundle in the hierarchy then null is returned.

Overrides:
getResourceBundle in class Category

info

public void info(Object message)
Log a message object with the INFO Level.

This method first checks if this category is INFO enabled by comparing the level of this category with INFO Level. If the category is INFO enabled, then it converts the message object passed as parameter to a string by invoking the appropriate ObjectRenderer. It proceeds to call all the registered appenders in this category and also higher in the hierarchy depending on the value of the additivity flag.

WARNING Note that passing a Throwable to this method will print the name of the Throwable but no stack trace. To print a stack trace use the Category.info(Object, Throwable) form instead.

Overrides:
info in class Category
Parameters:
message - the message object to log

info

public void info(Object message,
                 Throwable t)
Log a message object with the INFO level including the stack trace of the Throwable t passed as parameter.

See Category.info(Object) for more detailed information.

Overrides:
info in class Category
Parameters:
message - the message object to log.
t - the exception to log, including its stack trace.

isAttached

public boolean isAttached(Appender appender)
Is the appender passed as parameter attached to this category?

Specified by:
isAttached in interface AppenderAttachable
Overrides:
isAttached in class Category

isDebugEnabled

public boolean isDebugEnabled()
Check 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.

Overrides:
isDebugEnabled in class Category
Returns:
boolean - true if this category is debug enabled, false otherwise.

isEnabledFor

public boolean isEnabledFor(Priority level)
Check whether this category is enabled for a given Level passed as parameter. See also Category.isDebugEnabled().

Overrides:
isEnabledFor in class Category
Returns:
boolean True if this category is enabled for level.

isInfoEnabled

public boolean isInfoEnabled()
Check whether this category is enabled for the info Level. See also Category.isDebugEnabled().

Overrides:
isInfoEnabled in class Category
Returns:
boolean - true if this category is enabled for level info, false otherwise.

l7dlog

public void l7dlog(Priority priority,
                   String key,
                   Throwable t)
Log a localized message. The user supplied parameter key is replaced by its localized version from the resource bundle.

Overrides:
l7dlog in class Category
See Also:
Category.setResourceBundle(java.util.ResourceBundle)

l7dlog

public void l7dlog(Priority priority,
                   String key,
                   Object[] params,
                   Throwable t)
Log a localized and parameterized message. First, the user supplied key is searched in the resource bundle. Next, the resulting pattern is formatted using MessageFormat.format(String,Object[]) method with the user supplied object array params.

Overrides:
l7dlog in class Category

log

public void log(Priority priority,
                Object message,
                Throwable t)
This generic form is intended to be used by wrappers.

Overrides:
log in class Category

log

public void log(Priority priority,
                Object message)
This generic form is intended to be used by wrappers.

Overrides:
log in class Category

log

public void log(String callerFQCN,
                Priority level,
                Object message,
                Throwable t)
This is the most generic printing method. It is intended to be invoked by wrapper classes.

Overrides:
log in class Category
Parameters:
callerFQCN - The wrapper class' fully qualified class name.
level - The level of the logging request.
message - The message of the logging request.
t - The throwable of the logging request, may be null.

removeAllAppenders

public void removeAllAppenders()
Remove all previously added appenders from this Category instance.

This is useful when re-reading configuration information.

Specified by:
removeAllAppenders in interface AppenderAttachable
Overrides:
removeAllAppenders in class Category

removeAppender

public void removeAppender(Appender appender)
Remove the appender passed as parameter form the list of appenders.

Specified by:
removeAppender in interface AppenderAttachable
Overrides:
removeAppender in class Category

removeAppender

public void removeAppender(String name)
Remove the appender with the name passed as parameter form the list of appenders.

Specified by:
removeAppender in interface AppenderAttachable
Overrides:
removeAppender in class Category

setLevel

public void setLevel(Level level)
Set the level of this Category. If you are passing any of Level.DEBUG, Level.INFO, Level.WARN, Level.ERROR, Level.FATAL as a parameter, you need to case them as Level.

As in

    logger.setLevel((Level) Level.DEBUG); 

Null values are admitted.

Overrides:
setLevel in class Category

setPriority

public void setPriority(Priority priority)
Set the level of this Category.

Null values are admitted.

Overrides:
setPriority in class Category

setResourceBundle

public void setResourceBundle(ResourceBundle bundle)
Set the resource bundle to be used with localized logging methods Category.l7dlog(Priority,String,Throwable) and Category.l7dlog(Priority,String,Object[],Throwable).

Overrides:
setResourceBundle in class Category

warn

public void warn(Object message)
Log a message object with the WARN Level.

This method first checks if this category is WARN enabled by comparing the level of this category with WARN Level. If the category is WARN enabled, then it converts the message object passed as parameter to a string by invoking the appropriate ObjectRenderer. It proceeds to call all the registered appenders in this category and also higher in the hieararchy depending on the value of the additivity flag.

WARNING Note that passing a Throwable to this method will print the name of the Throwable but no stack trace. To print a stack trace use the Category.warn(Object, Throwable) form instead.

Overrides:
warn in class Category
Parameters:
message - the message object to log.

warn

public void warn(Object message,
                 Throwable t)
Log a message with the WARN level including the stack trace of the Throwable t passed as parameter.

See Category.warn(Object) for more detailed information.

Overrides:
warn in class Category
Parameters:
message - the message object to log.
t - the exception to log, including its stack trace.

trace

public void trace(Object message)
Log a message object with the TRACE level.

Overrides:
trace in class Logger
Parameters:
message - the message object to log.
See Also:
for an explanation of the logic applied.

trace

public void trace(Object message,
                  Throwable t)
Log a message object with the TRACE level including the stack trace of the Throwablet passed as parameter.

See Category.debug(Object) form for more detailed information.

Overrides:
trace in class Logger
Parameters:
message - the message object to log.
t - the exception to log, including its stack trace.

isTraceEnabled

public boolean isTraceEnabled()
Check whether this category is enabled for the TRACE Level.

Overrides:
isTraceEnabled in class Logger
Returns:
boolean - true if this category is enabled for level TRACE, false otherwise.


Copyright © 1999-2012 Apache Software Foundation. All Rights Reserved.