Method from org.apache.log4j.Category Detail: |
public synchronized void addAppender(Appender newAppender) {
if(aai == null) {
aai = new AppenderAttachableImpl();
}
aai.addAppender(newAppender);
repository.fireAddAppenderEvent(this, 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. |
public void assertLog(boolean assertion,
String msg) {
if(!assertion)
this.error(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. |
public void callAppenders(LoggingEvent event) {
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);
}
}
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. |
synchronized void closeNestedAppenders() {
Enumeration enumeration = this.getAllAppenders();
if(enumeration != null) {
while(enumeration.hasMoreElements()) {
Appender a = (Appender) enumeration.nextElement();
if(a instanceof AppenderAttachable) {
a.close();
}
}
}
}
Close all attached appenders implementing the AppenderAttachable
interface. |
public void debug(Object message) {
if(repository.isDisabled(Level.DEBUG_INT))
return;
if(Level.DEBUG.isGreaterOrEqual(this.getEffectiveLevel())) {
forcedLog(FQCN, Level.DEBUG, message, null);
}
}
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
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 Throwable to this
method will print the name of the Throwable but no
stack trace. To print a stack trace use the #debug(Object,
Throwable) form instead. |
public void debug(Object message,
Throwable t) {
if(repository.isDisabled(Level.DEBUG_INT))
return;
if(Level.DEBUG.isGreaterOrEqual(this.getEffectiveLevel()))
forcedLog(FQCN, Level.DEBUG, message, t);
}
|
public void error(Object message) {
if(repository.isDisabled(Level.ERROR_INT))
return;
if(Level.ERROR.isGreaterOrEqual(this.getEffectiveLevel()))
forcedLog(FQCN, Level.ERROR, message, null);
}
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 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 Throwable to this
method will print the name of the Throwable but no
stack trace. To print a stack trace use the #error(Object,
Throwable) form instead. |
public void error(Object message,
Throwable t) {
if(repository.isDisabled(Level.ERROR_INT))
return;
if(Level.ERROR.isGreaterOrEqual(this.getEffectiveLevel()))
forcedLog(FQCN, Level.ERROR, message, t);
}
|
public static Logger exists(String name) {
return LogManager.exists(name);
} Deprecated! Please - use LogManager#exists instead.
If the named category exists (in the default hierarchy) then it
returns a reference to the category, otherwise it returns
null . |
public void fatal(Object message) {
if(repository.isDisabled(Level.FATAL_INT))
return;
if(Level.FATAL.isGreaterOrEqual(this.getEffectiveLevel()))
forcedLog(FQCN, Level.FATAL, message, null);
}
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
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 Throwable to this
method will print the name of the Throwable but no stack trace. To
print a stack trace use the #fatal(Object, Throwable) form
instead. |
public void fatal(Object message,
Throwable t) {
if(repository.isDisabled(Level.FATAL_INT))
return;
if(Level.FATAL.isGreaterOrEqual(this.getEffectiveLevel()))
forcedLog(FQCN, Level.FATAL, message, t);
}
|
protected void forcedLog(String fqcn,
Priority level,
Object message,
Throwable t) {
callAppenders(new LoggingEvent(fqcn, this, level, message, t));
}
This method creates a new logging event and logs the event
without further checks. |
public boolean getAdditivity() {
return additive;
}
Get the additivity flag for this Category instance. |
public synchronized Enumeration getAllAppenders() {
if(aai == null)
return NullEnumeration.getInstance();
else
return aai.getAllAppenders();
}
Get the appenders contained in this category as an Enumeration . If no appenders can be found, then a NullEnumeration
is returned. |
public synchronized Appender getAppender(String name) {
if(aai == null || name == null)
return null;
return aai.getAppender(name);
}
|
public 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.
} Deprecated! Please - use the the #getEffectiveLevel method
instead.
|
public static Enumeration getCurrentCategories() {
return LogManager.getCurrentLoggers();
} Deprecated! Please - use LogManager#getCurrentLoggers() instead.
|
public static LoggerRepository getDefaultHierarchy() {
return LogManager.getLoggerRepository();
} Deprecated! Please - use LogManager#getLoggerRepository() instead.
Return the default Hierarchy instance. |
public Level getEffectiveLevel() {
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 LoggerRepository getHierarchy() {
return repository;
} Deprecated! Please - use #getLoggerRepository instead.
Return the the Hierarchy where this Category
instance is attached. |
public static Category getInstance(String name) {
return LogManager.getLogger(name);
} Deprecated! Make - sure to use Logger#getLogger(String) instead.
|
public static Category getInstance(Class clazz) {
return LogManager.getLogger(clazz);
} Deprecated! Please - make sure to use Logger#getLogger(Class) instead.
|
public final Level getLevel() {
return this.level;
}
Returns the assigned Level , if any, for this Category. |
public LoggerRepository getLoggerRepository() {
return repository;
}
|
public final String getName() {
return name;
}
Return the category name. |
public final Category getParent() {
return this.parent;
}
|
public final Level getPriority() {
return this.level;
} Deprecated! Please - use #getLevel instead.
|
public ResourceBundle getResourceBundle() {
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;
}
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. |
protected String getResourceBundleString(String key) {
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;
}
}
}
Returns the string resource coresponding to key in
this category's inherited resource bundle. See also #getResourceBundle .
If the resource cannot be found, then an error
message will be logged complaining about the missing resource. |
public static final Category getRoot() {
return LogManager.getRootLogger();
} Deprecated! Please - use Logger#getRootLogger() instead.
|
public void info(Object message) {
if(repository.isDisabled(Level.INFO_INT))
return;
if(Level.INFO.isGreaterOrEqual(this.getEffectiveLevel()))
forcedLog(FQCN, Level.INFO, message, null);
}
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
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 Throwable to this
method will print the name of the Throwable but no stack trace. To
print a stack trace use the #info(Object, Throwable) form
instead. |
public void info(Object message,
Throwable t) {
if(repository.isDisabled(Level.INFO_INT))
return;
if(Level.INFO.isGreaterOrEqual(this.getEffectiveLevel()))
forcedLog(FQCN, Level.INFO, message, t);
}
|
public boolean isAttached(Appender appender) {
if(appender == null || aai == null)
return false;
else {
return aai.isAttached(appender);
}
}
Is the appender passed as parameter attached to this category? |
public boolean isDebugEnabled() {
if(repository.isDisabled( Level.DEBUG_INT))
return false;
return Level.DEBUG.isGreaterOrEqual(this.getEffectiveLevel());
}
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. |
public boolean isEnabledFor(Priority level) {
if(repository.isDisabled(level.level))
return false;
return level.isGreaterOrEqual(this.getEffectiveLevel());
}
Check whether this category is enabled for a given Level passed as parameter.
See also #isDebugEnabled . |
public boolean isInfoEnabled() {
if(repository.isDisabled(Level.INFO_INT))
return false;
return Level.INFO.isGreaterOrEqual(this.getEffectiveLevel());
}
Check whether this category is enabled for the info Level.
See also #isDebugEnabled . |
public void l7dlog(Priority priority,
String key,
Throwable t) {
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);
}
}
Log a localized message. The user supplied parameter
key is replaced by its localized version from the
resource bundle. |
public void l7dlog(Priority priority,
String key,
Object[] params,
Throwable t) {
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);
}
}
Log a localized and parameterized message. First, the user
supplied key is searched in the resource
bundle. Next, the resulting pattern is formatted using
java.text.MessageFormat#format(String,Object[]) method with the
user supplied object array params . |
public void log(Priority priority,
Object message) {
if(repository.isDisabled(priority.level)) {
return;
}
if(priority.isGreaterOrEqual(this.getEffectiveLevel()))
forcedLog(FQCN, priority, message, null);
}
This generic form is intended to be used by wrappers. |
public void log(Priority priority,
Object message,
Throwable t) {
if(repository.isDisabled(priority.level)) {
return;
}
if(priority.isGreaterOrEqual(this.getEffectiveLevel()))
forcedLog(FQCN, priority, message, t);
}
This generic form is intended to be used by wrappers. |
public void log(String callerFQCN,
Priority level,
Object message,
Throwable t) {
if(repository.isDisabled(level.level)) {
return;
}
if(level.isGreaterOrEqual(this.getEffectiveLevel())) {
forcedLog(callerFQCN, level, message, t);
}
}
This is the most generic printing method. It is intended to be
invoked by wrapper classes. |
public synchronized void removeAllAppenders() {
if(aai != null) {
Vector appenders = new Vector();
for (Enumeration iter = aai.getAllAppenders(); iter != null && 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(Appender appender) {
if(appender == null || aai == null)
return;
boolean wasAttached = aai.isAttached(appender);
aai.removeAppender(appender);
if (wasAttached) {
fireRemoveAppenderEvent(appender);
}
}
Remove the appender passed as parameter form the list of appenders. |
public synchronized void removeAppender(String name) {
if(name == null || aai == null) return;
Appender appender = aai.getAppender(name);
aai.removeAppender(name);
if (appender != null) {
fireRemoveAppenderEvent(appender);
}
}
Remove the appender with the name passed as parameter form the
list of appenders. |
public void setAdditivity(boolean additive) {
this.additive = additive;
}
Set the additivity flag for this Category instance. |
final void setHierarchy(LoggerRepository repository) {
this.repository = repository;
}
Only the Hiearchy class can set the hiearchy of a
category. Default package access is MANDATORY here. |
public void setLevel(Level level) {
this.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. |
public void setPriority(Priority priority) {
this.level = (Level) priority;
} Deprecated! Please - use #setLevel instead.
|
public void setResourceBundle(ResourceBundle bundle) {
resourceBundle = bundle;
}
|
public static void shutdown() {
LogManager.shutdown();
} Deprecated! Please - use LogManager#shutdown() instead.
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 org.apache.log4j.net.SocketAppender
and 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. |
public void warn(Object message) {
if(repository.isDisabled( Level.WARN_INT))
return;
if(Level.WARN.isGreaterOrEqual(this.getEffectiveLevel()))
forcedLog(FQCN, Level.WARN, message, null);
}
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
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 Throwable to this
method will print the name of the Throwable but no stack trace. To
print a stack trace use the #warn(Object, Throwable) form
instead. |
public void warn(Object message,
Throwable t) {
if(repository.isDisabled(Level.WARN_INT))
return;
if(Level.WARN.isGreaterOrEqual(this.getEffectiveLevel()))
forcedLog(FQCN, Level.WARN, message, t);
}
|