public class Hierarchy extends Object implements LoggerRepository, RendererSupport, ThrowableRendererSupport
The casual user does not have to deal with this class directly.
The structure of the logger hierarchy is maintained by the getLogger(java.lang.String)
method. The hierarchy is such that
children link to their parent but parents do not have any pointers to their children. Moreover, loggers can be
instantiated in any order, in particular descendant before ancestor.
In case a descendant is created before a particular ancestor, then it creates a provision node for the ancestor and adds itself to the provision node. Other descendants of the same ancestor add themselves to the previously created provision node.
Constructor and Description |
---|
Hierarchy(Logger root)
Creates a new logger hierarchy.
|
Modifier and Type | Method and Description |
---|---|
void |
addHierarchyEventListener(HierarchyEventListener listener)
Add a
HierarchyEventListener event to the repository. |
void |
addRenderer(Class classToRender,
ObjectRenderer or)
Adds an object renderer for a specific class.
|
void |
clear()
This call will clear all logger definitions from the internal hashtable.
|
void |
emitNoAppenderWarning(Category cat) |
Logger |
exists(String name)
Tests if the named logger exists in the hierarchy.
|
void |
fireAddAppenderEvent(Category logger,
Appender appender) |
Enumeration |
getCurrentCategories()
Deprecated.
Please use
getCurrentLoggers() instead. |
Enumeration |
getCurrentLoggers()
Gets all the currently defined categories in this hierarchy as an
Enumeration . |
Logger |
getLogger(String name)
Gets a new logger instance named as the first parameter using the default factory.
|
Logger |
getLogger(String name,
LoggerFactory factory)
Gets a new logger instance named as the first parameter using
factory . |
RendererMap |
getRendererMap()
Gets the renderer map for this hierarchy.
|
Logger |
getRootLogger()
Gets the root of this hierarchy.
|
Level |
getThreshold()
Gets a
Level representation of the enable state. |
ThrowableRenderer |
getThrowableRenderer()
Get throwable renderer.
|
boolean |
isDisabled(int level)
This method will return
true if this repository is disabled for level object passed as
parameter and false otherwise. |
void |
overrideAsNeeded(String override)
Deprecated.
Deprecated with no replacement.
|
void |
resetConfiguration()
Resets all values contained in this hierarchy instance to their default.
|
void |
setDisableOverride(String override)
Deprecated.
Deprecated with no replacement.
|
void |
setRenderer(Class renderedClass,
ObjectRenderer renderer)
Used by subclasses to add a renderer to the hierarchy passed as parameter.
|
void |
setThreshold(Level level)
Enable logging for logging requests with level
l or higher. |
void |
setThreshold(String levelStr)
The string form of
setThreshold(Level) . |
void |
setThrowableRenderer(ThrowableRenderer throwableRenderer)
Set throwable renderer.
|
void |
shutdown()
Shutting down a hierarchy will safely close and remove all appenders in all categories including the root
logger.
|
void |
shutdown(ClassLoader classLoader) |
public Hierarchy(Logger root)
root
- The root of the new hierarchy.public void addHierarchyEventListener(HierarchyEventListener listener)
LoggerRepository
HierarchyEventListener
event to the repository.addHierarchyEventListener
in interface LoggerRepository
listener
- The listenerpublic void addRenderer(Class classToRender, ObjectRenderer or)
public void clear()
You should really know what you are doing before invoking this method.
public void emitNoAppenderWarning(Category cat)
emitNoAppenderWarning
in interface LoggerRepository
public Logger exists(String name)
null
.exists
in interface LoggerRepository
name
- The name of the logger to search for.public void fireAddAppenderEvent(Category logger, Appender appender)
fireAddAppenderEvent
in interface LoggerRepository
@Deprecated public Enumeration getCurrentCategories()
getCurrentLoggers()
instead.LoggerRepository
LoggerRepository.getCurrentLoggers()
instead.getCurrentCategories
in interface LoggerRepository
public Enumeration getCurrentLoggers()
Enumeration
.
The root logger is not included in the returned Enumeration
.
getCurrentLoggers
in interface LoggerRepository
public Logger getLogger(String name)
If a logger of that name already exists, then it will be returned. Otherwise, a new logger will be instantiated and then linked with its existing ancestors as well as children.
getLogger
in interface LoggerRepository
name
- The name of the logger to retrieve.public Logger getLogger(String name, LoggerFactory factory)
factory
.
If a logger of that name already exists, then it will be returned. Otherwise, a new logger will be instantiated by
the factory
parameter and linked with its existing ancestors as well as children.
getLogger
in interface LoggerRepository
name
- The name of the logger to retrieve.factory
- The factory that will make the new logger instance.public RendererMap getRendererMap()
getRendererMap
in interface RendererSupport
public Logger getRootLogger()
getRootLogger
in interface LoggerRepository
public Level getThreshold()
Level
representation of the enable
state.getThreshold
in interface LoggerRepository
public ThrowableRenderer getThrowableRenderer()
getThrowableRenderer
in interface ThrowableRendererSupport
public boolean isDisabled(int level)
true
if this repository is disabled for level
object passed as
parameter and false
otherwise. See also the threshold
emthod.isDisabled
in interface LoggerRepository
level
- The level@Deprecated public void overrideAsNeeded(String override)
public void resetConfiguration()
null
, sets their additivity flag to
true
and sets the level of the root logger to DEBUG
. Moreover, message disabling is
set its default "off" value.
Existing categories are not removed. They are just reset.
This method should be used sparingly and with care as it will block all logging until it is completed.
resetConfiguration
in interface LoggerRepository
@Deprecated public void setDisableOverride(String override)
public void setRenderer(Class renderedClass, ObjectRenderer renderer)
setRenderer
in interface RendererSupport
public void setThreshold(Level level)
l
or higher. By default all levels are enabled.setThreshold
in interface LoggerRepository
level
- The minimum level for which logging requests are sent to their appenders.public void setThreshold(String levelStr)
setThreshold(Level)
.setThreshold
in interface LoggerRepository
levelStr
- The threshold valuepublic void setThrowableRenderer(ThrowableRenderer throwableRenderer)
setThrowableRenderer
in interface ThrowableRendererSupport
throwableRenderer
- renderer, may be null.public void shutdown()
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 logger and again to a nested appender.
shutdown
in interface LoggerRepository
public void shutdown(ClassLoader classLoader)
Copyright © 1999-2022 The Apache Software Foundation. All Rights Reserved.
Apache Logging, Apache Log4j, Log4j, Apache, the Apache feather logo, the Apache Logging project logo, and the Apache Log4j logo are trademarks of The Apache Software Foundation.