📄 category.java
字号:
/**
Log a message object with the <code>FATAL</code> level including
the stack trace of the {@link Throwable} <code>t</code> passed as
parameter.
<p>See {@link #fatal(Object)} for more detailed information.
@param message the message object to log.
@param t the exception to log, including its stack trace. */
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);
}
/**
This method creates a new logging event and logs the event
without further checks. */
protected
void forcedLog(String fqcn, Priority level, Object message, Throwable t) {
callAppenders(new LoggingEvent(fqcn, this, level, message, t));
}
/**
Get the additivity flag for this Category instance.
*/
public
boolean getAdditivity() {
return additive;
}
/**
Get the appenders contained in this category as an {@link
Enumeration}. If no appenders can be found, then a {@link NullEnumeration}
is returned.
@return Enumeration An enumeration of the appenders in this category. */
synchronized
public
Enumeration getAllAppenders() {
if(aai == null)
return NullEnumeration.getInstance();
else
return aai.getAllAppenders();
}
/**
Look for the appender named as <code>name</code>.
<p>Return the appender with that name if in the list. Return
<code>null</code> otherwise. */
synchronized
public
Appender getAppender(String name) {
if(aai == null || name == null)
return null;
return aai.getAppender(name);
}
/**
Starting from this category, search the category hierarchy for a
non-null level and return it. Otherwise, return the level of the
root category.
<p>The Category class is designed so that this method executes as
quickly as possible.
*/
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.
}
/**
*
* @deprecated Please use the the {@link #getEffectiveLevel} method
* instead.
* */
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.
}
/**
Returns all the currently defined categories in the default
hierarchy as an {@link java.util.Enumeration Enumeration}.
<p>The root category is <em>not</em> included in the returned
{@link Enumeration}.
@deprecated Please use {@link LogManager#getCurrentLoggers()} instead.
*/
public
static
Enumeration getCurrentCategories() {
return LogManager.getCurrentLoggers();
}
/**
Return the default Hierarchy instance.
@deprecated Please use {@link LogManager#getLoggerRepository()} instead.
@since 1.0
*/
public
static
LoggerRepository getDefaultHierarchy() {
return LogManager.getLoggerRepository();
}
/**
Return the the {@link Hierarchy} where this <code>Category</code>
instance is attached.
@deprecated Please use {@link #getLoggerRepository} instead.
@since 1.1 */
public
LoggerRepository getHierarchy() {
return repository;
}
/**
Return the the {@link LoggerRepository} where this
<code>Category</code> is attached.
@since 1.2 */
public
LoggerRepository getLoggerRepository() {
return repository;
}
/**
Retrieve a category with named as the <code>name</code>
parameter. If the named category already exists, then the
existing instance will be reutrned. Otherwise, a new instance is
created.
By default, categories do not have a set level but inherit
it from the hierarchy. This is one of the central features of
log4j.
<b>Deprecated</b> Please use {@link Logger#getLogger(String)}
instead.
@param name The name of the category to retrieve. */
public
static
Category getInstance(String name) {
return LogManager.getLogger(name);
}
/**
Shorthand for <code>getInstance(clazz.getName())</code>.
@param clazz The name of <code>clazz</code> will be used as the
name of the category to retrieve. See {@link
#getInstance(String)} for more detailed information.
<b>Deprecated</b> Please use {@link Logger#getLogger(Class)} instead.
@since 1.0 */
public
static
Category getInstance(Class clazz) {
return LogManager.getLogger(clazz);
}
/**
Return the category name. */
public
final
String getName() {
return name;
}
/**
Returns the parent of this category. Note that the parent of a
given category may change during the lifetime of the category.
<p>The root category will return <code>null</code>.
@since 1.2
*/
final
public
Category getParent() {
return this.parent;
}
/**
Returns the assigned {@link Level}, if any, for this Category.
@return Level - the assigned Level, can be <code>null</code>.
*/
final
public
Level getLevel() {
return this.level;
}
/**
@deprecated Please use {@link #getLevel} instead.
*/
final
public
Level getPriority() {
return this.level;
}
/**
Return the root of the default category hierrachy.
<p>The root category is always instantiated and available. It's
name is "root".
<p>Nevertheless, calling {@link #getInstance
Category.getInstance("root")} does not retrieve the root category
but a category just under root named "root".
<b>Deprecated</b> Use {@link Logger#getRootLogger()} instead.
*/
final
public
static
Category getRoot() {
return LogManager.getRootLogger();
}
/**
Return the <em>inherited</em> {@link ResourceBundle} for this
category.
<p>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 <code>null</code> is returned.
@since 0.9.0 */
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;
}
/**
Returns the string resource coresponding to <code>key</code> in
this category's inherited resource bundle. See also {@link
#getResourceBundle}.
<p>If the resource cannot be found, then an {@link #error error}
message will be logged complaining about the missing resource.
*/
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;
}
}
}
/**
Log a message object with the {@link Level#INFO INFO} Level.
<p>This method first checks if this category is <code>INFO</code>
enabled by comparing the level of this category with {@link
Level#INFO INFO} Level. If the category is <code>INFO</code>
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.
<p><b>WARNING</b> 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.
@param message the message object to log */
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 <code>INFO</code> level including
the stack trace of the {@link Throwable} <code>t</code> passed as
parameter.
<p>See {@link #info(Object)} for more detailed information.
@param message the message object to log.
@param t the exception to log, including its stack trace. */
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);
}
/**
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -