|
Log4j 1.1.3 | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--org.apache.log4j.Hierarchy
This class is specialized in retrieving categories by name and also maintaining the category hierarchy.
The casual user should not have to deal with this class directly. In fact, up until version 0.9.0, this class had default package access. However, if you are in an environment where multiple applications run in the same VM, then read on.
The structure of the category hierarchy is maintained by the
getInstance(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, categories 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.
See the code below for further details.
Constructor Summary | |
Hierarchy(Category root)
Create a new Category hierarchy. |
Method Summary | |
void |
addRenderer(Class classToRender,
ObjectRenderer or)
Add an object renderer for a specific class. |
void |
clear()
This call will clear all category definitions from the internal hashtable. |
void |
disable(Priority p)
Disable all logging requests of priority equal to or below the priority parameter p , for
all categories in this hierarchy. |
void |
disable(String priorityStr)
Similar to disable(Priority) except that the priority
argument is given as a String. |
void |
disableAll()
Disable all logging requests regardless of category and priority. |
void |
disableDebug()
Disable all logging requests of priority DEBUG regardless of category. |
void |
disableInfo()
Disable all logging requests of priority INFO and below regardless of category. |
void |
enableAll()
Undoes the effect of calling any of disable(java.lang.String) , disableAll() , disableDebug() and disableInfo()
methods. |
Category |
exists(String name)
Check if the named category exists in the hierarchy. |
Enumeration |
getCurrentCategories()
Returns all the currently defined categories in this hierarchy as an Enumeration .
|
Category |
getInstance(String name)
Return a new category instance named as the first parameter using the default factory. |
Category |
getInstance(String name,
CategoryFactory factory)
Return a new category instance named as the first parameter using factory .
|
RendererMap |
getRendererMap()
Get the renderer map for this hierarchy. |
Category |
getRoot()
Get the root of this hierarchy. |
boolean |
isDisabled(int level)
|
void |
overrideAsNeeded(String override)
Override the shipped code flag if the override
parameter is not null.
|
void |
resetConfiguration()
Reset all values contained in this hierarchy instance to their default. |
void |
setCategoryFactory(CategoryFactory factory)
Set the default CategoryFactory instance. |
void |
setDisableOverride(String override)
Set the disable override value given a string. |
void |
shutdown()
Shutting down a hierarchy will safely close and remove all appenders in all categories including the root category. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public Hierarchy(Category root)
root
- The root of the new hierarchy.Method Detail |
public void addRenderer(Class classToRender, ObjectRenderer or)
public void clear()
You should really know what you are doing before invoking this method.
public Category exists(String name)
null
.name
- The name of the category to search for.public void disable(String priorityStr)
disable(Priority)
except that the priority
argument is given as a String.public void disable(Priority p)
p
, for
all categories in this hierarchy. Logging requests of
higher priority then p
remain unaffected.
Nevertheless, if the BasicConfigurator.DISABLE_OVERRIDE_KEY
system property is set to
"true" or any value other than "false", then logging requests are
evaluated as usual, i.e. according to the Basic Selection Rule.
The "disable" family of methods are there for speed. They allow printing methods such as debug, info, etc. to return immediately after an integer comparison without walking the category hierarchy. In most modern computers an integer comparison is measured in nanoseconds where as a category walk is measured in units of microseconds.
Other configurators define alternate ways of overriding the
disable override flag. See PropertyConfigurator
and
DOMConfigurator
.
public void disableAll()
disable(java.lang.String)
with the
argument Priority.FATAL
, the highest possible priority.public void disableDebug()
disable(java.lang.String)
with the argument Priority.DEBUG
.public void disableInfo()
Invoking this method is equivalent to calling disable(Priority)
with the argument Priority.INFO
.
public void enableAll()
disable(java.lang.String)
, disableAll()
, disableDebug()
and disableInfo()
methods. More precisely, invoking this method sets the Category
class internal variable called disable
to its
default "off" value.public void overrideAsNeeded(String override)
override
parameter is not null.
If override
is null then there is nothing to do.
Otherwise, set Category.shippedCode to false if override has a
value other than "false".
public Category getInstance(String name)
If a category of that name already exists, then it will be returned. Otherwise, a new category will be instantiated and then linked with its existing ancestors as well as children.
name
- The name of the category to retrieve.public Category getInstance(String name, CategoryFactory factory)
factory
.
If a category of that name already exists, then it will be
returned. Otherwise, a new category will be instantiated by the
factory
parameter and linked with its existing
ancestors as well as children.
name
- The name of the category to retrieve.factory
- The factory that will make the new category instance.public Enumeration getCurrentCategories()
Enumeration
.
The root category is not included in the returned
Enumeration
.
public boolean isDisabled(int level)
public RendererMap getRendererMap()
public Category getRoot()
public void resetConfiguration()
null
,
sets their additivity flag to true
and sets the priority
of the root category 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.
public void setCategoryFactory(CategoryFactory factory)
public void setDisableOverride(String override)
public void shutdown()
Some appenders such as 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.
|
Log4j 1.1.3 | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |