Package org.apache.log4j
Class Category
- java.lang.Object
-
- org.apache.log4j.Category
-
- All Implemented Interfaces:
AppenderAttachable
- Direct Known Subclasses:
Logger
public class Category extends Object implements AppenderAttachable
Implementation of the Category class for compatibility, despite it having been deprecated a long, long time ago.
-
-
Field Summary
Fields Modifier and Type Field Description protected boolean
additive
Additivity is set to true by default, that is children inherit the appenders of their ancestors by default.protected ResourceBundle
bundle
Resource bundle for localized messages.protected Level
level
The assigned level of this category.protected String
name
The name of this category.protected Category
parent
The parent of this category.protected LoggerRepository
repository
Categories need to know what Hierarchy they are in.
-
Constructor Summary
Constructors Modifier Constructor Description protected
Category(String name)
Constructor exposed by Log4j 1.2.protected
Category(LoggerContext context, String name)
Constructor used by Logger to specify a LoggerContext.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description void
addAppender(Appender appender)
AddnewAppender
to the list of appenders of this Category instance.void
assertLog(boolean assertion, String msg)
void
callAppenders(LoggingEvent event)
Call the appenders in the hierrachy starting atthis
.void
debug(Object message)
void
debug(Object message, Throwable t)
void
error(Object message)
void
error(Object message, Throwable t)
static Logger
exists(String name)
Deprecated.Please useLogManager.exists(String)
instead.void
fatal(Object message)
void
fatal(Object message, Throwable t)
void
forcedLog(String fqcn, Priority level, Object message, Throwable t)
boolean
getAdditivity()
Enumeration
getAllAppenders()
Get the appenders contained in this category as anEnumeration
.Appender
getAppender(String name)
Look for the appender named asname
.Priority
getChainedPriority()
static Enumeration
getCurrentCategories()
Deprecated.Please useLogManager.getCurrentLoggers()
instead.static LoggerRepository
getDefaultHierarchy()
Deprecated.Please useLogManager.getLoggerRepository()
instead.Level
getEffectiveLevel()
LoggerRepository
getHierarchy()
Deprecated.Please usegetLoggerRepository()
instead.static Category
getInstance(Class clazz)
static Category
getInstance(String name)
Level
getLevel()
LoggerRepository
getLoggerRepository()
Gets the theLoggerRepository
where thisCategory
is attached.String
getName()
Category
getParent()
Level
getPriority()
ResourceBundle
getResourceBundle()
static Category
getRoot()
void
info(Object message)
void
info(Object message, Throwable t)
boolean
isAttached(Appender appender)
Is the appender passed as parameter attached to this category?boolean
isDebugEnabled()
boolean
isEnabledFor(Priority level)
boolean
isErrorEnabled()
boolean
isFatalEnabled()
boolean
isInfoEnabled()
boolean
isWarnEnabled()
void
l7dlog(Priority priority, String key, Object[] params, Throwable t)
void
l7dlog(Priority priority, String key, Throwable t)
void
log(String fqcn, Priority priority, Object message, Throwable t)
void
log(Priority priority, Object message)
void
log(Priority priority, Object message, Throwable t)
void
removeAllAppenders()
Removes all previously added appenders from this Category instance.void
removeAppender(String name)
Removes the appender with the name passed as parameter form the list of appenders.void
removeAppender(Appender appender)
Removes the appender passed as parameter form the list of appenders.void
setAdditivity(boolean additivity)
void
setLevel(Level level)
void
setPriority(Priority priority)
void
setResourceBundle(ResourceBundle bundle)
static void
shutdown()
Shuts down the current configuration.void
warn(Object message)
void
warn(Object message, Throwable t)
-
-
-
Field Detail
-
name
protected String name
The name of this category.
-
additive
protected boolean additive
Additivity is set to true by default, that is children inherit the appenders of their ancestors by default. If this variable is set tofalse
then the appenders found in the ancestors of this category are not used. However, the children of this category will inherit its appenders, unless the children have their additivity flag set tofalse
too. See the user manual for more details.
-
level
protected volatile Level level
The assigned level of this category. Thelevel
variable need not be assigned a value in which case it is inherited form the hierarchy.
-
parent
protected volatile Category parent
The parent of this category. All categories have at least one ancestor which is the root category.
-
bundle
protected ResourceBundle bundle
Resource bundle for localized messages.
-
repository
protected LoggerRepository repository
Categories need to know what Hierarchy they are in.
-
-
Constructor Detail
-
Category
protected Category(LoggerContext context, String name)
Constructor used by Logger to specify a LoggerContext.- Parameters:
context
- The LoggerContext.name
- The name of the Logger.
-
Category
protected Category(String name)
Constructor exposed by Log4j 1.2.- Parameters:
name
- The name of the Logger.
-
-
Method Detail
-
exists
@Deprecated public static Logger exists(String name)
Deprecated.Please useLogManager.exists(String)
instead.Tests if the named category exists (in the default hierarchy).- Parameters:
name
- The name to test.- Returns:
- Whether the name exists.
- Since:
- 0.8.5
-
getCurrentCategories
@Deprecated public static Enumeration getCurrentCategories()
Deprecated.Please useLogManager.getCurrentLoggers()
instead.Returns all the currently defined categories in the default hierarchy as anEnumeration
.The root category is not included in the returned
Enumeration
.- Returns:
- and Enumeration of the Categories.
-
getDefaultHierarchy
@Deprecated public static LoggerRepository getDefaultHierarchy()
Deprecated.Please useLogManager.getLoggerRepository()
instead.Gets the default LoggerRepository instance.- Returns:
- the default LoggerRepository instance.
- Since:
- 1.0
-
getRoot
public static Category getRoot()
-
shutdown
public static void shutdown()
Shuts down the current configuration.
-
addAppender
public void addAppender(Appender appender)
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
- Parameters:
appender
- The Appender to add.
-
assertLog
public void assertLog(boolean assertion, 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.- Parameters:
assertion
- The assertion.msg
- The message to print ifassertion
is false.- Since:
- 1.2
-
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.
- Parameters:
event
- the event to log.
-
debug
public void debug(Object message)
-
error
public void error(Object message)
-
fatal
public void fatal(Object message)
-
getAdditivity
public boolean getAdditivity()
-
getAllAppenders
public 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
- Returns:
- Enumeration An enumeration of the appenders in this category.
-
getAppender
public Appender getAppender(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
- Parameters:
name
- The name of the Appender.- Returns:
- The Appender.
-
getChainedPriority
public Priority getChainedPriority()
-
getEffectiveLevel
public Level getEffectiveLevel()
-
getHierarchy
@Deprecated public LoggerRepository getHierarchy()
Deprecated.Please usegetLoggerRepository()
instead.Gets the theLoggerRepository
where thisCategory
instance is attached.- Since:
- 1.1
-
getLevel
public final Level getLevel()
-
getLoggerRepository
public LoggerRepository getLoggerRepository()
Gets the theLoggerRepository
where thisCategory
is attached.- Since:
- 1.2
-
getName
public final String getName()
-
getParent
public final Category getParent()
-
getPriority
public final Level getPriority()
-
getResourceBundle
public ResourceBundle getResourceBundle()
-
info
public void info(Object message)
-
isAttached
public boolean isAttached(Appender appender)
Is the appender passed as parameter attached to this category?- Specified by:
isAttached
in interfaceAppenderAttachable
- Parameters:
appender
- The Appender to add.- Returns:
- true if the appender is attached.
-
isDebugEnabled
public boolean isDebugEnabled()
-
isEnabledFor
public boolean isEnabledFor(Priority level)
-
isErrorEnabled
public boolean isErrorEnabled()
-
isFatalEnabled
public boolean isFatalEnabled()
-
isInfoEnabled
public boolean isInfoEnabled()
-
isWarnEnabled
public boolean isWarnEnabled()
-
removeAllAppenders
public void removeAllAppenders()
Removes all previously added appenders from this Category instance.This is useful when re-reading configuration information.
- Specified by:
removeAllAppenders
in interfaceAppenderAttachable
-
removeAppender
public void removeAppender(Appender appender)
Removes the appender passed as parameter form the list of appenders.- Specified by:
removeAppender
in interfaceAppenderAttachable
- Parameters:
appender
- The Appender to remove.- Since:
- 0.8.2
-
removeAppender
public void removeAppender(String name)
Removes the appender with the name passed as parameter form the list of appenders.- Specified by:
removeAppender
in interfaceAppenderAttachable
- Parameters:
name
- The Appender to remove.- Since:
- 0.8.2
-
setAdditivity
public void setAdditivity(boolean additivity)
-
setLevel
public void setLevel(Level level)
-
setPriority
public void setPriority(Priority priority)
-
setResourceBundle
public void setResourceBundle(ResourceBundle bundle)
-
warn
public void warn(Object message)
-
-