Class Hierarchy
- java.lang.Object
-
- org.apache.log4j.Hierarchy
-
- All Implemented Interfaces:
LoggerRepository,RendererSupport,ThrowableRendererSupport
public class Hierarchy extends java.lang.Object implements LoggerRepository, RendererSupport, ThrowableRendererSupport
This class is specialized in retrieving loggers by name and also maintaining the logger hierarchy.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.
- Author:
- Ceki Gülcü
-
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidaddHierarchyEventListener(HierarchyEventListener listener)Add aHierarchyEventListenerevent to the repository.voidaddRenderer(java.lang.Class classToRender, ObjectRenderer or)Add an object renderer for a specific class.voidclear()This call will clear all logger definitions from the internal hashtable.voidemitNoAppenderWarning(Category cat)Loggerexists(java.lang.String name)Check if the named logger exists in the hierarchy.voidfireAddAppenderEvent(Category logger, Appender appender)java.util.EnumerationgetCurrentCategories()Deprecated.Please usegetCurrentLoggers()instead.java.util.EnumerationgetCurrentLoggers()Returns all the currently defined categories in this hierarchy as anEnumeration.LoggergetLogger(java.lang.String name)Return a new logger instance named as the first parameter using the default factory.LoggergetLogger(java.lang.String name, LoggerFactory factory)Return a new logger instance named as the first parameter usingfactory.RendererMapgetRendererMap()Get the renderer map for this hierarchy.LoggergetRootLogger()Get the root of this hierarchy.LevelgetThreshold()Returns aLevelrepresentation of theenablestate.ThrowableRenderergetThrowableRenderer()Get throwable renderer.booleanisDisabled(int level)This method will returntrueif this repository is disabled forlevelobject passed as parameter andfalseotherwise.voidoverrideAsNeeded(java.lang.String override)Deprecated.Deprecated with no replacement.voidresetConfiguration()Reset all values contained in this hierarchy instance to their default.voidsetDisableOverride(java.lang.String override)Deprecated.Deprecated with no replacement.voidsetRenderer(java.lang.Class renderedClass, ObjectRenderer renderer)Used by subclasses to add a renderer to the hierarchy passed as parameter.voidsetThreshold(java.lang.String levelStr)The string form ofsetThreshold(Level).voidsetThreshold(Level l)Enable logging for logging requests with levellor higher.voidsetThrowableRenderer(ThrowableRenderer renderer)Set throwable renderer.voidshutdown()Shutting down a hierarchy will safely close and remove all appenders in all categories including the root logger.
-
-
-
Constructor Detail
-
Hierarchy
public Hierarchy(Logger root)
Create a new logger hierarchy.- Parameters:
root- The root of the new hierarchy.
-
-
Method Detail
-
addRenderer
public void addRenderer(java.lang.Class classToRender, ObjectRenderer or)Add an object renderer for a specific class.
-
addHierarchyEventListener
public void addHierarchyEventListener(HierarchyEventListener listener)
Description copied from interface:LoggerRepositoryAdd aHierarchyEventListenerevent to the repository.- Specified by:
addHierarchyEventListenerin interfaceLoggerRepository
-
clear
public void clear()
This call will clear all logger definitions from the internal hashtable. Invoking this method will irrevocably mess up the logger hierarchy.You should really know what you are doing before invoking this method.
- Since:
- 0.9.0
-
emitNoAppenderWarning
public void emitNoAppenderWarning(Category cat)
- Specified by:
emitNoAppenderWarningin interfaceLoggerRepository
-
exists
public Logger exists(java.lang.String name)
Check if the named logger exists in the hierarchy. If so return its reference, otherwise returnsnull.- Specified by:
existsin interfaceLoggerRepository- Parameters:
name- The name of the logger to search for.
-
setThreshold
public void setThreshold(java.lang.String levelStr)
The string form ofsetThreshold(Level).- Specified by:
setThresholdin interfaceLoggerRepository
-
setThreshold
public void setThreshold(Level l)
Enable logging for logging requests with levellor higher. By default all levels are enabled.- Specified by:
setThresholdin interfaceLoggerRepository- Parameters:
l- The minimum level for which logging requests are sent to their appenders.
-
fireAddAppenderEvent
public void fireAddAppenderEvent(Category logger, Appender appender)
- Specified by:
fireAddAppenderEventin interfaceLoggerRepository
-
getThreshold
public Level getThreshold()
Returns aLevelrepresentation of theenablestate.- Specified by:
getThresholdin interfaceLoggerRepository- Since:
- 1.2
-
getLogger
public Logger getLogger(java.lang.String name)
Return a new logger instance named as the first parameter using the default factory.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.
- Specified by:
getLoggerin interfaceLoggerRepository- Parameters:
name- The name of the logger to retrieve.
-
getLogger
public Logger getLogger(java.lang.String name, LoggerFactory factory)
Return a new logger instance named as the first parameter usingfactory.If a logger of that name already exists, then it will be returned. Otherwise, a new logger will be instantiated by the
factoryparameter and linked with its existing ancestors as well as children.- Specified by:
getLoggerin interfaceLoggerRepository- Parameters:
name- The name of the logger to retrieve.factory- The factory that will make the new logger instance.
-
getCurrentLoggers
public java.util.Enumeration getCurrentLoggers()
Returns all the currently defined categories in this hierarchy as anEnumeration.The root logger is not included in the returned
Enumeration.- Specified by:
getCurrentLoggersin interfaceLoggerRepository
-
getCurrentCategories
public java.util.Enumeration getCurrentCategories()
Deprecated.Please usegetCurrentLoggers()instead.Description copied from interface:LoggerRepositoryDeprecated. Please useLoggerRepository.getCurrentLoggers()instead.- Specified by:
getCurrentCategoriesin interfaceLoggerRepository
-
getRendererMap
public RendererMap getRendererMap()
Get the renderer map for this hierarchy.- Specified by:
getRendererMapin interfaceRendererSupport
-
getRootLogger
public Logger getRootLogger()
Get the root of this hierarchy.- Specified by:
getRootLoggerin interfaceLoggerRepository- Since:
- 0.9.0
-
isDisabled
public boolean isDisabled(int level)
This method will returntrueif this repository is disabled forlevelobject passed as parameter andfalseotherwise. See also thethresholdemthod.- Specified by:
isDisabledin interfaceLoggerRepository
-
overrideAsNeeded
public void overrideAsNeeded(java.lang.String override)
Deprecated.Deprecated with no replacement.
-
resetConfiguration
public void resetConfiguration()
Reset all values contained in this hierarchy instance to their default. This removes all appenders from all categories, sets the level of all non-root categories tonull, sets their additivity flag totrueand sets the level of the root logger toDEBUG. 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.
- Specified by:
resetConfigurationin interfaceLoggerRepository- Since:
- 0.8.5
-
setDisableOverride
public void setDisableOverride(java.lang.String override)
Deprecated.Deprecated with no replacement.Does nothing.
-
setRenderer
public void setRenderer(java.lang.Class renderedClass, ObjectRenderer renderer)Used by subclasses to add a renderer to the hierarchy passed as parameter.- Specified by:
setRendererin interfaceRendererSupport
-
setThrowableRenderer
public void setThrowableRenderer(ThrowableRenderer renderer)
Set throwable renderer.- Specified by:
setThrowableRendererin interfaceThrowableRendererSupport- Parameters:
renderer- renderer, may be null.
-
getThrowableRenderer
public ThrowableRenderer getThrowableRenderer()
Get throwable renderer.- Specified by:
getThrowableRendererin interfaceThrowableRendererSupport- Returns:
- throwable renderer, may be null.
-
shutdown
public void shutdown()
Shutting down a hierarchy will safely close and remove all appenders in all categories including the root logger.Some appenders such as
SocketAppenderandAsyncAppenderneed to be closed before the application exists. Otherwise, pending logging events might be lost.The
shutdownmethod 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.- Specified by:
shutdownin interfaceLoggerRepository- Since:
- 1.0
-
-