Methods Summary |
---|
public synchronized void | addAppender(org.apache.log4j.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.
if(aai == null) {
aai = new AppenderAttachableImpl();
}
aai.addAppender(newAppender);
repository.fireAddAppenderEvent(this, newAppender);
|
public void | assertLog(boolean assertion, java.lang.String msg)If assertion parameter is false , then
logs msg as an {@link #error(Object) error} statement.
The assert method has been renamed to
assertLog because assert is a language
reserved word in JDK 1.4.
if(!assertion)
this.error(msg);
|
public void | callAppenders(org.apache.log4j.spi.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.
int writes = 0;
for(Category c = this; c != null; c=c.parent) {
// Protected against simultaneous call to addAppender, removeAppender,...
synchronized(c) {
if(c.aai != null) {
writes += c.aai.appendLoopOnAppenders(event);
}
if(!c.additive) {
break;
}
}
}
if(writes == 0) {
repository.emitNoAppenderWarning(this);
}
|
synchronized void | closeNestedAppenders()Close all attached appenders implementing the AppenderAttachable
interface.
Enumeration enumeration = this.getAllAppenders();
if(enumeration != null) {
while(enumeration.hasMoreElements()) {
Appender a = (Appender) enumeration.nextElement();
if(a instanceof AppenderAttachable) {
a.close();
}
}
}
|
public void | debug(java.lang.Object message)Log a message object with the {@link Level#DEBUG DEBUG} level.
This method first checks if this category is DEBUG
enabled by comparing the level of this category with the {@link
Level#DEBUG DEBUG} level. If this category is
DEBUG enabled, then it converts the message object
(passed as parameter) to a string by invoking the appropriate
{@link org.apache.log4j.or.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 {@link Throwable} to this
method will print the name of the Throwable but no
stack trace. To print a stack trace use the {@link #debug(Object,
Throwable)} form instead.
if(repository.isDisabled(Level.DEBUG_INT))
return;
if(Level.DEBUG.isGreaterOrEqual(this.getEffectiveLevel())) {
forcedLog(FQCN, Level.DEBUG, message, null);
}
|
public void | debug(java.lang.Object message, java.lang.Throwable t)Log a message object with the DEBUG level including
the stack trace of the {@link Throwable} t passed as
parameter.
See {@link #debug(Object)} form for more detailed information.
if(repository.isDisabled(Level.DEBUG_INT))
return;
if(Level.DEBUG.isGreaterOrEqual(this.getEffectiveLevel()))
forcedLog(FQCN, Level.DEBUG, message, t);
|
public void | error(java.lang.Object message)Log a message object with the {@link Level#ERROR ERROR} Level.
This method first checks if this category is ERROR
enabled by comparing the level of this category with {@link
Level#ERROR ERROR} Level. If this category is ERROR
enabled, then it converts the message object passed as parameter
to a string by invoking the appropriate {@link
org.apache.log4j.or.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 {@link Throwable} to this
method will print the name of the Throwable but no
stack trace. To print a stack trace use the {@link #error(Object,
Throwable)} form instead.
if(repository.isDisabled(Level.ERROR_INT))
return;
if(Level.ERROR.isGreaterOrEqual(this.getEffectiveLevel()))
forcedLog(FQCN, Level.ERROR, message, null);
|
public void | error(java.lang.Object message, java.lang.Throwable t)Log a message object with the ERROR level including
the stack trace of the {@link Throwable} t passed as
parameter.
See {@link #error(Object)} form for more detailed information.
if(repository.isDisabled(Level.ERROR_INT))
return;
if(Level.ERROR.isGreaterOrEqual(this.getEffectiveLevel()))
forcedLog(FQCN, Level.ERROR, message, t);
|
public static org.apache.log4j.Logger | exists(java.lang.String name)If the named category exists (in the default hierarchy) then it
returns a reference to the category, otherwise it returns
null .
return LogManager.exists(name);
|
public void | fatal(java.lang.Object message)Log a message object with the {@link Level#FATAL FATAL} Level.
This method first checks if this category is FATAL
enabled by comparing the level of this category with {@link
Level#FATAL FATAL} Level. If the category is FATAL
enabled, then it converts the message object passed as parameter
to a string by invoking the appropriate
{@link org.apache.log4j.or.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 {@link Throwable} to this
method will print the name of the Throwable but no stack trace. To
print a stack trace use the {@link #fatal(Object, Throwable)} form
instead.
if(repository.isDisabled(Level.FATAL_INT))
return;
if(Level.FATAL.isGreaterOrEqual(this.getEffectiveLevel()))
forcedLog(FQCN, Level.FATAL, message, null);
|
public void | fatal(java.lang.Object message, java.lang.Throwable t)Log a message object with the FATAL level including
the stack trace of the {@link Throwable} t passed as
parameter.
See {@link #fatal(Object)} for more detailed information.
if(repository.isDisabled(Level.FATAL_INT))
return;
if(Level.FATAL.isGreaterOrEqual(this.getEffectiveLevel()))
forcedLog(FQCN, Level.FATAL, message, t);
|
private void | fireRemoveAppenderEvent(org.apache.log4j.Appender appender)LoggerRepository forgot the fireRemoveAppenderEvent method,
if using the stock Hierarchy implementation, then call its fireRemove.
Custom repositories can implement HierarchyEventListener if they
want remove notifications.
if (appender != null) {
if (repository instanceof Hierarchy) {
((Hierarchy) repository).fireRemoveAppenderEvent(this, appender);
} else if (repository instanceof HierarchyEventListener) {
((HierarchyEventListener) repository).removeAppenderEvent(this, appender);
}
}
|
protected void | forcedLog(java.lang.String fqcn, org.apache.log4j.Priority level, java.lang.Object message, java.lang.Throwable t)This method creates a new logging event and logs the event
without further checks.
callAppenders(new LoggingEvent(fqcn, this, level, message, t));
|
public boolean | getAdditivity()Get the additivity flag for this Category instance.
return additive;
|
public synchronized java.util.Enumeration | getAllAppenders()Get the appenders contained in this category as an {@link
Enumeration}. If no appenders can be found, then a {@link NullEnumeration}
is returned.
if(aai == null)
return NullEnumeration.getInstance();
else
return aai.getAllAppenders();
|
public synchronized org.apache.log4j.Appender | getAppender(java.lang.String name)Look for the appender named as name .
Return the appender with that name if in the list. Return
null otherwise.
if(aai == null || name == null)
return null;
return aai.getAppender(name);
|
public org.apache.log4j.Priority | getChainedPriority()
for(Category c = this; c != null; c=c.parent) {
if(c.level != null)
return c.level;
}
return null; // If reached will cause an NullPointerException.
|
public static java.util.Enumeration | getCurrentCategories()Returns all the currently defined categories in the default
hierarchy as an {@link java.util.Enumeration Enumeration}.
The root category is not included in the returned
{@link Enumeration}.
return LogManager.getCurrentLoggers();
|
public static org.apache.log4j.spi.LoggerRepository | getDefaultHierarchy()Return the default Hierarchy instance.
return LogManager.getLoggerRepository();
|
public org.apache.log4j.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.
for(Category c = this; c != null; c=c.parent) {
if(c.level != null)
return c.level;
}
return null; // If reached will cause an NullPointerException.
|
public org.apache.log4j.spi.LoggerRepository | getHierarchy()Return the the {@link Hierarchy} where this Category
instance is attached.
return repository;
|
public static org.apache.log4j.Category | getInstance(java.lang.String name)
return LogManager.getLogger(name);
|
public static org.apache.log4j.Category | getInstance(java.lang.Class clazz)
return LogManager.getLogger(clazz);
|
public final org.apache.log4j.Level | getLevel()Returns the assigned {@link Level}, if any, for this Category.
return this.level;
|
public org.apache.log4j.spi.LoggerRepository | getLoggerRepository()Return the the {@link LoggerRepository} where this
Category is attached.
return repository;
|
public final java.lang.String | getName()Return the category name.
return name;
|
public final org.apache.log4j.Category | getParent()Returns the parent of this category. Note that the parent of a
given category may change during the lifetime of the category.
The root category will return null .
return this.parent;
|
public final org.apache.log4j.Level | getPriority()
return this.level;
|
public java.util.ResourceBundle | getResourceBundle()Return the inherited {@link 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.
for(Category c = this; c != null; c=c.parent) {
if(c.resourceBundle != null)
return c.resourceBundle;
}
// It might be the case that there is no resource bundle
return null;
|
protected java.lang.String | getResourceBundleString(java.lang.String key)Returns the string resource coresponding to key in
this category's inherited resource bundle. See also {@link
#getResourceBundle}.
If the resource cannot be found, then an {@link #error error}
message will be logged complaining about the missing resource.
ResourceBundle rb = getResourceBundle();
// This is one of the rare cases where we can use logging in order
// to report errors from within log4j.
if(rb == null) {
//if(!hierarchy.emittedNoResourceBundleWarning) {
//error("No resource bundle has been set for category "+name);
//hierarchy.emittedNoResourceBundleWarning = true;
//}
return null;
}
else {
try {
return rb.getString(key);
}
catch(MissingResourceException mre) {
error("No resource is associated with key \""+key+"\".");
return null;
}
}
|
public static final org.apache.log4j.Category | getRoot()
return LogManager.getRootLogger();
|
public void | info(java.lang.Object message)Log a message object with the {@link Level#INFO INFO} Level.
This method first checks if this category is INFO
enabled by comparing the level of this category with {@link
Level#INFO INFO} Level. If the category is INFO
enabled, then it converts the message object passed as parameter
to a string by invoking the appropriate
{@link org.apache.log4j.or.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 {@link Throwable} to this
method will print the name of the Throwable but no stack trace. To
print a stack trace use the {@link #info(Object, Throwable)} form
instead.
if(repository.isDisabled(Level.INFO_INT))
return;
if(Level.INFO.isGreaterOrEqual(this.getEffectiveLevel()))
forcedLog(FQCN, Level.INFO, message, null);
|
public void | info(java.lang.Object message, java.lang.Throwable t)Log a message object with the INFO level including
the stack trace of the {@link Throwable} t passed as
parameter.
See {@link #info(Object)} for more detailed information.
if(repository.isDisabled(Level.INFO_INT))
return;
if(Level.INFO.isGreaterOrEqual(this.getEffectiveLevel()))
forcedLog(FQCN, Level.INFO, message, t);
|
public boolean | isAttached(org.apache.log4j.Appender appender)Is the appender passed as parameter attached to this category?
if(appender == null || aai == null)
return false;
else {
return aai.isAttached(appender);
}
|
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.
if(repository.isDisabled( Level.DEBUG_INT))
return false;
return Level.DEBUG.isGreaterOrEqual(this.getEffectiveLevel());
|
public boolean | isEnabledFor(org.apache.log4j.Priority level)Check whether this category is enabled for a given {@link
Level} passed as parameter.
See also {@link #isDebugEnabled}.
if(repository.isDisabled(level.level))
return false;
return level.isGreaterOrEqual(this.getEffectiveLevel());
|
public boolean | isInfoEnabled()Check whether this category is enabled for the info Level.
See also {@link #isDebugEnabled}.
if(repository.isDisabled(Level.INFO_INT))
return false;
return Level.INFO.isGreaterOrEqual(this.getEffectiveLevel());
|
public void | l7dlog(org.apache.log4j.Priority priority, java.lang.String key, java.lang.Throwable t)Log a localized message. The user supplied parameter
key is replaced by its localized version from the
resource bundle.
if(repository.isDisabled(priority.level)) {
return;
}
if(priority.isGreaterOrEqual(this.getEffectiveLevel())) {
String msg = getResourceBundleString(key);
// if message corresponding to 'key' could not be found in the
// resource bundle, then default to 'key'.
if(msg == null) {
msg = key;
}
forcedLog(FQCN, priority, msg, t);
}
|
public void | l7dlog(org.apache.log4j.Priority priority, java.lang.String key, java.lang.Object[] params, java.lang.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
{@link java.text.MessageFormat#format(String,Object[])} method with the
user supplied object array params .
if(repository.isDisabled(priority.level)) {
return;
}
if(priority.isGreaterOrEqual(this.getEffectiveLevel())) {
String pattern = getResourceBundleString(key);
String msg;
if(pattern == null)
msg = key;
else
msg = java.text.MessageFormat.format(pattern, params);
forcedLog(FQCN, priority, msg, t);
}
|
public void | log(org.apache.log4j.Priority priority, java.lang.Object message, java.lang.Throwable t)This generic form is intended to be used by wrappers.
if(repository.isDisabled(priority.level)) {
return;
}
if(priority.isGreaterOrEqual(this.getEffectiveLevel()))
forcedLog(FQCN, priority, message, t);
|
public void | log(org.apache.log4j.Priority priority, java.lang.Object message)This generic form is intended to be used by wrappers.
if(repository.isDisabled(priority.level)) {
return;
}
if(priority.isGreaterOrEqual(this.getEffectiveLevel()))
forcedLog(FQCN, priority, message, null);
|
public void | log(java.lang.String callerFQCN, org.apache.log4j.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.
if(repository.isDisabled(level.level)) {
return;
}
if(level.isGreaterOrEqual(this.getEffectiveLevel())) {
forcedLog(callerFQCN, level, message, t);
}
|
public synchronized void | removeAllAppenders()Remove all previously added appenders from this Category
instance.
This is useful when re-reading configuration information.
if(aai != null) {
Vector appenders = new Vector();
for (Enumeration iter = aai.getAllAppenders(); iter.hasMoreElements();) {
appenders.add(iter.nextElement());
}
aai.removeAllAppenders();
for(Enumeration iter = appenders.elements(); iter.hasMoreElements();) {
fireRemoveAppenderEvent((Appender) iter.nextElement());
}
aai = null;
}
|
public synchronized void | removeAppender(org.apache.log4j.Appender appender)Remove the appender passed as parameter form the list of appenders.
if(appender == null || aai == null)
return;
boolean wasAttached = aai.isAttached(appender);
aai.removeAppender(appender);
if (wasAttached) {
fireRemoveAppenderEvent(appender);
}
|
public synchronized void | removeAppender(java.lang.String name)Remove the appender with the name passed as parameter form the
list of appenders.
if(name == null || aai == null) return;
Appender appender = aai.getAppender(name);
aai.removeAppender(name);
if (appender != null) {
fireRemoveAppenderEvent(appender);
}
|
public void | setAdditivity(boolean additive)Set the additivity flag for this Category instance.
this.additive = additive;
|
final void | setHierarchy(org.apache.log4j.spi.LoggerRepository repository)Only the Hiearchy class can set the hiearchy of a
category. Default package access is MANDATORY here.
this.repository = repository;
|
public void | setLevel(org.apache.log4j.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.
this.level = level;
|
public void | setPriority(org.apache.log4j.Priority priority)Set the level of this Category.
Null values are admitted.
this.level = (Level) priority;
|
public void | setResourceBundle(java.util.ResourceBundle bundle)Set the resource bundle to be used with localized logging
methods {@link #l7dlog(Priority,String,Throwable)} and {@link
#l7dlog(Priority,String,Object[],Throwable)}.
resourceBundle = bundle;
|
public static void | shutdown()Calling this method will safely close and remove all
appenders in all the categories including root contained in the
default hierachy.
Some appenders such as {@link org.apache.log4j.net.SocketAppender}
and {@link AsyncAppender} need to be closed before the
application exists. Otherwise, pending logging events might be
lost.
The shutdown method is careful to close nested
appenders before closing regular appenders. This is allows
configurations where a regular appender is attached to a category
and again to a nested appender.
LogManager.shutdown();
|
public void | warn(java.lang.Object message)Log a message object with the {@link Level#WARN WARN} Level.
This method first checks if this category is WARN
enabled by comparing the level of this category with {@link
Level#WARN WARN} Level. If the category is WARN
enabled, then it converts the message object passed as parameter
to a string by invoking the appropriate
{@link org.apache.log4j.or.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 {@link Throwable} to this
method will print the name of the Throwable but no stack trace. To
print a stack trace use the {@link #warn(Object, Throwable)} form
instead.
if(repository.isDisabled( Level.WARN_INT))
return;
if(Level.WARN.isGreaterOrEqual(this.getEffectiveLevel()))
forcedLog(FQCN, Level.WARN, message, null);
|
public void | warn(java.lang.Object message, java.lang.Throwable t)Log a message with the WARN level including the
stack trace of the {@link Throwable} t passed as
parameter.
See {@link #warn(Object)} for more detailed information.
if(repository.isDisabled(Level.WARN_INT))
return;
if(Level.WARN.isGreaterOrEqual(this.getEffectiveLevel()))
forcedLog(FQCN, Level.WARN, message, t);
|