Class NOPLogger
- java.lang.Object
-
- org.apache.log4j.Category
-
- org.apache.log4j.Logger
-
- 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
Constructors Constructor Description NOPLogger(NOPLoggerRepository repo, java.lang.String name)Create instance of Logger.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddAppender(Appender newAppender)AddnewAppenderto the list of appenders of this Category instance.voidassertLog(boolean assertion, java.lang.String msg)voidcallAppenders(LoggingEvent event)Call the appenders in the hierrachy starting atthis.voiddebug(java.lang.Object message)Log a message object with theDEBUGlevel.voiddebug(java.lang.Object message, java.lang.Throwable t)Log a message object with theDEBUGlevel including the stack trace of theThrowabletpassed as parameter.voiderror(java.lang.Object message)Log a message object with theERRORLevel.voiderror(java.lang.Object message, java.lang.Throwable t)Log a message object with theERRORlevel including the stack trace of theThrowabletpassed as parameter.voidfatal(java.lang.Object message)Log a message object with theFATALLevel.voidfatal(java.lang.Object message, java.lang.Throwable t)Log a message object with theFATALlevel including the stack trace of theThrowabletpassed as parameter.java.util.EnumerationgetAllAppenders()Get the appenders contained in this category as anEnumeration.AppendergetAppender(java.lang.String name)Look for the appender named asname.PrioritygetChainedPriority()LevelgetEffectiveLevel()Starting from this category, search the category hierarchy for a non-null level and return it.java.util.ResourceBundlegetResourceBundle()Return the inheritedResourceBundlefor this category.voidinfo(java.lang.Object message)Log a message object with theINFOLevel.voidinfo(java.lang.Object message, java.lang.Throwable t)Log a message object with theINFOlevel including the stack trace of theThrowabletpassed as parameter.booleanisAttached(Appender appender)Is the appender passed as parameter attached to this category?booleanisDebugEnabled()Check whether this category is enabled for theDEBUGLevel.booleanisEnabledFor(Priority level)Check whether this category is enabled for a givenLevelpassed as parameter.booleanisInfoEnabled()Check whether this category is enabled for the info Level.booleanisTraceEnabled()Check whether this category is enabled for the TRACE Level.voidl7dlog(Priority priority, java.lang.String key, java.lang.Object[] params, java.lang.Throwable t)Log a localized and parameterized message.voidl7dlog(Priority priority, java.lang.String key, java.lang.Throwable t)Log a localized message.voidlog(java.lang.String callerFQCN, Priority level, java.lang.Object message, java.lang.Throwable t)This is the most generic printing method.voidlog(Priority priority, java.lang.Object message)This generic form is intended to be used by wrappers.voidlog(Priority priority, java.lang.Object message, java.lang.Throwable t)This generic form is intended to be used by wrappers.voidremoveAllAppenders()Remove all previously added appenders from this Category instance.voidremoveAppender(java.lang.String name)Remove the appender with the name passed as parameter form the list of appenders.voidremoveAppender(Appender appender)Remove the appender passed as parameter form the list of appenders.voidsetLevel(Level level)Set the level of this Category.voidsetPriority(Priority priority)Set the level of this Category.voidsetResourceBundle(java.util.ResourceBundle bundle)Set the resource bundle to be used with localized logging methodsCategory.l7dlog(Priority, String, Throwable)andCategory.l7dlog(Priority, String, Object[], Throwable).voidtrace(java.lang.Object message)Log a message object with theTRACElevel.voidtrace(java.lang.Object message, java.lang.Throwable t)Log a message object with theTRACElevel including the stack trace of theThrowabletpassed as parameter.voidwarn(java.lang.Object message)Log a message object with theWARNLevel.voidwarn(java.lang.Object message, java.lang.Throwable t)Log a message with theWARNlevel including the stack trace of theThrowabletpassed 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
-
-
-
-
Constructor Detail
-
NOPLogger
public NOPLogger(NOPLoggerRepository repo, java.lang.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)
AddnewAppenderto the list of appenders of this Category instance.If
newAppenderis already in the list of appenders, then it won't be added again.- Specified by:
addAppenderin interfaceAppenderAttachable- Overrides:
addAppenderin classCategory
-
assertLog
public void assertLog(boolean assertion, java.lang.String msg)Ifassertionparameter isfalse, then logsmsgas anerrorstatement.The
assertmethod has been renamed toassertLogbecauseassertis a language reserved word in JDK 1.4.
-
callAppenders
public void callAppenders(LoggingEvent event)
Call the appenders in the hierrachy starting atthis. 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:
callAppendersin classCategory- Parameters:
event- the event to log.
-
debug
public void debug(java.lang.Object message)
Log a message object with theDEBUGlevel.This method first checks if this category is
DEBUGenabled by comparing the level of this category with theDEBUGlevel. If this category isDEBUGenabled, then it converts the message object (passed as parameter) to a string by invoking the appropriateObjectRenderer. 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
Throwableto this method will print the name of theThrowablebut no stack trace. To print a stack trace use theCategory.debug(Object, Throwable)form instead.
-
debug
public void debug(java.lang.Object message, java.lang.Throwable t)Log a message object with theDEBUGlevel including the stack trace of theThrowabletpassed as parameter.See
Category.debug(Object)form for more detailed information.
-
error
public void error(java.lang.Object message)
Log a message object with theERRORLevel.This method first checks if this category is
ERRORenabled by comparing the level of this category withERRORLevel. If this category isERRORenabled, then it converts the message object passed as parameter to a string by invoking the appropriateObjectRenderer. 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
Throwableto this method will print the name of theThrowablebut no stack trace. To print a stack trace use theCategory.error(Object, Throwable)form instead.
-
error
public void error(java.lang.Object message, java.lang.Throwable t)Log a message object with theERRORlevel including the stack trace of theThrowabletpassed as parameter.See
Category.error(Object)form for more detailed information.
-
fatal
public void fatal(java.lang.Object message)
Log a message object with theFATALLevel.This method first checks if this category is
FATALenabled by comparing the level of this category withFATALLevel. If the category isFATALenabled, then it converts the message object passed as parameter to a string by invoking the appropriateObjectRenderer. 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
Throwableto this method will print the name of the Throwable but no stack trace. To print a stack trace use theCategory.fatal(Object, Throwable)form instead.
-
fatal
public void fatal(java.lang.Object message, java.lang.Throwable t)Log a message object with theFATALlevel including the stack trace of theThrowabletpassed as parameter.See
Category.fatal(Object)for more detailed information.
-
getAllAppenders
public java.util.Enumeration getAllAppenders()
Get the appenders contained in this category as anEnumeration. If no appenders can be found, then aNullEnumerationis returned.- Specified by:
getAllAppendersin interfaceAppenderAttachable- Overrides:
getAllAppendersin classCategory- Returns:
- Enumeration An enumeration of the appenders in this category.
-
getAppender
public Appender getAppender(java.lang.String name)
Look for the appender named asname.Return the appender with that name if in the list. Return
nullotherwise.- Specified by:
getAppenderin interfaceAppenderAttachable- Overrides:
getAppenderin classCategory
-
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:
getEffectiveLevelin classCategory
-
getChainedPriority
public Priority getChainedPriority()
- Overrides:
getChainedPriorityin classCategory
-
getResourceBundle
public java.util.ResourceBundle getResourceBundle()
Return the inheritedResourceBundlefor 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
nullis returned.- Overrides:
getResourceBundlein classCategory
-
info
public void info(java.lang.Object message)
Log a message object with theINFOLevel.This method first checks if this category is
INFOenabled by comparing the level of this category withINFOLevel. If the category isINFOenabled, then it converts the message object passed as parameter to a string by invoking the appropriateObjectRenderer. 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
Throwableto this method will print the name of the Throwable but no stack trace. To print a stack trace use theCategory.info(Object, Throwable)form instead.
-
info
public void info(java.lang.Object message, java.lang.Throwable t)Log a message object with theINFOlevel including the stack trace of theThrowabletpassed as parameter.See
Category.info(Object)for more detailed information.
-
isAttached
public boolean isAttached(Appender appender)
Is the appender passed as parameter attached to this category?- Specified by:
isAttachedin interfaceAppenderAttachable- Overrides:
isAttachedin classCategory
-
isDebugEnabled
public boolean isDebugEnabled()
Check whether this category is enabled for theDEBUGLevel.This function is intended to lessen the computational cost of disabled log debug statements.
For some
catCategory 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 thecatis debug enabled, you will incur the cost of evaluating whether the category is debug enabled twice. Once inisDebugEnabledand once in thedebug. This is an insignificant overhead since evaluating a category takes about 1%% of the time it takes to actually log.- Overrides:
isDebugEnabledin classCategory- Returns:
- boolean -
trueif this category is debug enabled,falseotherwise.
-
isEnabledFor
public boolean isEnabledFor(Priority level)
Check whether this category is enabled for a givenLevelpassed as parameter.See also
Category.isDebugEnabled().- Overrides:
isEnabledForin classCategory- 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 alsoCategory.isDebugEnabled().- Overrides:
isInfoEnabledin classCategory- Returns:
- boolean -
trueif this category is enabled for level info,falseotherwise.
-
l7dlog
public void l7dlog(Priority priority, java.lang.String key, java.lang.Throwable t)
Log a localized message. The user supplied parameterkeyis replaced by its localized version from the resource bundle.- Overrides:
l7dlogin classCategory- See Also:
Category.setResourceBundle(java.util.ResourceBundle)
-
l7dlog
public void l7dlog(Priority priority, java.lang.String key, java.lang.Object[] params, java.lang.Throwable t)
Log a localized and parameterized message. First, the user suppliedkeyis searched in the resource bundle. Next, the resulting pattern is formatted usingMessageFormat.format(String, Object[])method with the user supplied object arrayparams.
-
log
public void log(Priority priority, java.lang.Object message, java.lang.Throwable t)
This generic form is intended to be used by wrappers.
-
log
public void log(Priority priority, java.lang.Object message)
This generic form is intended to be used by wrappers.
-
log
public void log(java.lang.String callerFQCN, Priority level, java.lang.Object message, java.lang.Throwable t)This is the most generic printing method. It is intended to be invoked by wrapper classes.
-
removeAllAppenders
public void removeAllAppenders()
Remove all previously added appenders from this Category instance.This is useful when re-reading configuration information.
- Specified by:
removeAllAppendersin interfaceAppenderAttachable- Overrides:
removeAllAppendersin classCategory
-
removeAppender
public void removeAppender(Appender appender)
Remove the appender passed as parameter form the list of appenders.- Specified by:
removeAppenderin interfaceAppenderAttachable- Overrides:
removeAppenderin classCategory
-
removeAppender
public void removeAppender(java.lang.String name)
Remove the appender with the name passed as parameter form the list of appenders.- Specified by:
removeAppenderin interfaceAppenderAttachable- Overrides:
removeAppenderin classCategory
-
setLevel
public void setLevel(Level level)
Set the level of this Category. If you are passing any ofLevel.DEBUG,Level.INFO,Level.WARN,Level.ERROR,Level.FATALas a parameter, you need to case them as Level.As in
logger.setLevel((Level) Level.DEBUG);
Null values are admitted.
-
setPriority
public void setPriority(Priority priority)
Set the level of this Category.Null values are admitted.
- Overrides:
setPriorityin classCategory
-
setResourceBundle
public void setResourceBundle(java.util.ResourceBundle bundle)
Set the resource bundle to be used with localized logging methodsCategory.l7dlog(Priority, String, Throwable)andCategory.l7dlog(Priority, String, Object[], Throwable).- Overrides:
setResourceBundlein classCategory
-
warn
public void warn(java.lang.Object message)
Log a message object with theWARNLevel.This method first checks if this category is
WARNenabled by comparing the level of this category withWARNLevel. If the category isWARNenabled, then it converts the message object passed as parameter to a string by invoking the appropriateObjectRenderer. 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
Throwableto this method will print the name of the Throwable but no stack trace. To print a stack trace use theCategory.warn(Object, Throwable)form instead.
-
warn
public void warn(java.lang.Object message, java.lang.Throwable t)Log a message with theWARNlevel including the stack trace of theThrowabletpassed as parameter.See
Category.warn(Object)for more detailed information.
-
trace
public void trace(java.lang.Object message)
Log a message object with theTRACElevel.- Overrides:
tracein classLogger- Parameters:
message- the message object to log.- See Also:
for an explanation of the logic applied.
-
trace
public void trace(java.lang.Object message, java.lang.Throwable t)Log a message object with theTRACElevel including the stack trace of theThrowabletpassed as parameter.See
Category.debug(Object)form for more detailed information.
-
isTraceEnabled
public boolean isTraceEnabled()
Check whether this category is enabled for the TRACE Level.- Overrides:
isTraceEnabledin classLogger- Returns:
- boolean -
trueif this category is enabled for level TRACE,falseotherwise.
-
-