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 void
addAppender(Appender newAppender)
AddnewAppender
to the list of appenders of this Category instance.void
assertLog(boolean assertion, java.lang.String msg)
void
callAppenders(LoggingEvent event)
Call the appenders in the hierrachy starting atthis
.void
debug(java.lang.Object message)
Log a message object with theDEBUG
level.void
debug(java.lang.Object message, java.lang.Throwable t)
Log a message object with theDEBUG
level including the stack trace of theThrowable
t
passed as parameter.void
error(java.lang.Object message)
Log a message object with theERROR
Level.void
error(java.lang.Object message, java.lang.Throwable t)
Log a message object with theERROR
level including the stack trace of theThrowable
t
passed as parameter.void
fatal(java.lang.Object message)
Log a message object with theFATAL
Level.void
fatal(java.lang.Object message, java.lang.Throwable t)
Log a message object with theFATAL
level including the stack trace of theThrowable
t
passed as parameter.java.util.Enumeration
getAllAppenders()
Get the appenders contained in this category as anEnumeration
.Appender
getAppender(java.lang.String name)
Look for the appender named asname
.Priority
getChainedPriority()
Level
getEffectiveLevel()
Starting from this category, search the category hierarchy for a non-null level and return it.java.util.ResourceBundle
getResourceBundle()
Return the inheritedResourceBundle
for this category.void
info(java.lang.Object message)
Log a message object with theINFO
Level.void
info(java.lang.Object message, java.lang.Throwable t)
Log a message object with theINFO
level including the stack trace of theThrowable
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 theDEBUG
Level.boolean
isEnabledFor(Priority level)
Check whether this category is enabled for a givenLevel
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, java.lang.String key, java.lang.Object[] params, java.lang.Throwable t)
Log a localized and parameterized message.void
l7dlog(Priority priority, java.lang.String key, java.lang.Throwable t)
Log a localized message.void
log(java.lang.String callerFQCN, Priority level, java.lang.Object message, java.lang.Throwable t)
This is the most generic printing method.void
log(Priority priority, java.lang.Object message)
This generic form is intended to be used by wrappers.void
log(Priority priority, java.lang.Object message, java.lang.Throwable t)
This generic form is intended to be used by wrappers.void
removeAllAppenders()
Remove all previously added appenders from this Category instance.void
removeAppender(java.lang.String name)
Remove the appender with the name passed as parameter form the list of appenders.void
removeAppender(Appender appender)
Remove the appender 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(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)
.void
trace(java.lang.Object message)
Log a message object with theTRACE
level.void
trace(java.lang.Object message, java.lang.Throwable t)
Log a message object with theTRACE
level including the stack trace of theThrowable
t
passed as parameter.void
warn(java.lang.Object message)
Log a message object with theWARN
Level.void
warn(java.lang.Object message, java.lang.Throwable t)
Log a message with theWARN
level including the stack trace of theThrowable
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
-
-
-
-
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)
AddnewAppender
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 interfaceAppenderAttachable
- Overrides:
addAppender
in classCategory
-
assertLog
public void assertLog(boolean assertion, java.lang.String msg)
Ifassertion
parameter isfalse
, then logsmsg
as anerror
statement.The
assert
method has been renamed toassertLog
becauseassert
is 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:
callAppenders
in classCategory
- Parameters:
event
- the event to log.
-
debug
public void debug(java.lang.Object message)
Log a message object with theDEBUG
level.This method first checks if this category is
DEBUG
enabled by comparing the level of this category with theDEBUG
level. If this category isDEBUG
enabled, 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
Throwable
to this method will print the name of theThrowable
but 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 theDEBUG
level including the stack trace of theThrowable
t
passed as parameter.See
Category.debug(Object)
form for more detailed information.
-
error
public void error(java.lang.Object message)
Log a message object with theERROR
Level.This method first checks if this category is
ERROR
enabled by comparing the level of this category withERROR
Level. If this category isERROR
enabled, 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
Throwable
to this method will print the name of theThrowable
but 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 theERROR
level including the stack trace of theThrowable
t
passed as parameter.See
Category.error(Object)
form for more detailed information.
-
fatal
public void fatal(java.lang.Object message)
Log a message object with theFATAL
Level.This method first checks if this category is
FATAL
enabled by comparing the level of this category withFATAL
Level. If the category isFATAL
enabled, 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
Throwable
to 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 theFATAL
level including the stack trace of theThrowable
t
passed 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 aNullEnumeration
is returned.- Specified by:
getAllAppenders
in interfaceAppenderAttachable
- Overrides:
getAllAppenders
in 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
null
otherwise.- Specified by:
getAppender
in interfaceAppenderAttachable
- Overrides:
getAppender
in 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:
getEffectiveLevel
in classCategory
-
getChainedPriority
public Priority getChainedPriority()
- Overrides:
getChainedPriority
in classCategory
-
getResourceBundle
public java.util.ResourceBundle getResourceBundle()
Return the inheritedResourceBundle
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 classCategory
-
info
public void info(java.lang.Object message)
Log a message object with theINFO
Level.This method first checks if this category is
INFO
enabled by comparing the level of this category withINFO
Level. If the category isINFO
enabled, 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
Throwable
to 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 theINFO
level including the stack trace of theThrowable
t
passed 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:
isAttached
in interfaceAppenderAttachable
- Overrides:
isAttached
in classCategory
-
isDebugEnabled
public boolean isDebugEnabled()
Check whether this category is enabled for theDEBUG
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 thecat
is debug enabled, you will incur the cost of evaluating whether the category is debug enabled twice. Once inisDebugEnabled
and once in thedebug
. This is an insignificant overhead since evaluating a category takes about 1%% of the time it takes to actually log.- Overrides:
isDebugEnabled
in classCategory
- 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 givenLevel
passed as parameter.See also
Category.isDebugEnabled()
.- Overrides:
isEnabledFor
in 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:
isInfoEnabled
in classCategory
- Returns:
- boolean -
true
if this category is enabled for level info,false
otherwise.
-
l7dlog
public void l7dlog(Priority priority, java.lang.String key, java.lang.Throwable t)
Log a localized message. The user supplied parameterkey
is replaced by its localized version from the resource bundle.- Overrides:
l7dlog
in 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 suppliedkey
is 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:
removeAllAppenders
in interfaceAppenderAttachable
- Overrides:
removeAllAppenders
in classCategory
-
removeAppender
public void removeAppender(Appender appender)
Remove the appender passed as parameter form the list of appenders.- Specified by:
removeAppender
in interfaceAppenderAttachable
- Overrides:
removeAppender
in 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:
removeAppender
in interfaceAppenderAttachable
- Overrides:
removeAppender
in 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.FATAL
as 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:
setPriority
in 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:
setResourceBundle
in classCategory
-
warn
public void warn(java.lang.Object message)
Log a message object with theWARN
Level.This method first checks if this category is
WARN
enabled by comparing the level of this category withWARN
Level. If the category isWARN
enabled, 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
Throwable
to 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 theWARN
level including the stack trace of theThrowable
t
passed as parameter.See
Category.warn(Object)
for more detailed information.
-
trace
public void trace(java.lang.Object message)
Log a message object with theTRACE
level.- Overrides:
trace
in 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 theTRACE
level including the stack trace of theThrowable
t
passed 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:
isTraceEnabled
in classLogger
- Returns:
- boolean -
true
if this category is enabled for level TRACE,false
otherwise.
-
-