Class Hierarchy
- All Implemented Interfaces:
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.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static classprivate static classPrivate LogManager. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final WeakHashMap<LoggerContext, ConcurrentMap<String, Logger>> private final LoggerFactory(package private) boolean(package private) boolean(package private) Hashtableprivate final Vectorprivate static final Hierarchy.PrivateLoggerAdapter(package private) RendererMap(package private) Logger(package private) Level(package private) intprivate ThrowableRenderer -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidAdd aHierarchyEventListenerevent to the repository.voidaddRenderer(Class classToRender, ObjectRenderer or) Adds an object renderer for a specific class.voidclear()This call will clear all logger definitions from the internal hashtable.voidTests if the named logger exists in the hierarchy.(package private) Loggerexists(String name, ClassLoader classLoader) (package private) Loggerexists(String name, LoggerContext loggerContext) voidfireAddAppenderEvent(Category logger, Appender appender) (package private) voidfireRemoveAppenderEvent(Category logger, Appender appender) (package private) static LoggerContext(package private) LoggerContextgetContext(ClassLoader classLoader) Deprecated.Gets all the currently defined categories in this hierarchy as anEnumeration.(package private) static LoggergetInstance(LoggerContext context, String name) (package private) static LoggergetInstance(LoggerContext context, String name, Hierarchy.PrivateLoggerAdapter factory) (package private) static LoggergetInstance(LoggerContext context, String name, LoggerFactory factory) Gets a new logger instance named as the first parameter using the default factory.(package private) LoggergetLogger(String name, ClassLoader classLoader) getLogger(String name, LoggerFactory factory) Gets a new logger instance named as the first parameter usingfactory.(package private) LoggergetLogger(String name, LoggerFactory factory, ClassLoader classLoader) (package private) static ConcurrentMap<String, Logger> getLoggersMap(LoggerContext context) Gets the renderer map for this hierarchy.Gets the root of this hierarchy.(package private) LoggergetRootLogger(ClassLoader classLoader) (package private) static LoggergetRootLogger(LoggerContext context) Gets aLevelrepresentation of theenablestate.Get throwable renderer.booleanisDisabled(int level) This method will returntrueif this repository is disabled forlevelobject passed as parameter andfalseotherwise.voidoverrideAsNeeded(String override) Deprecated.Deprecated with no replacement.voidResets all values contained in this hierarchy instance to their default.(package private) voidresetConfiguration(ClassLoader classLoader) (package private) voidresetConfiguration(LoggerContext loggerContext) voidsetDisableOverride(String override) Deprecated.Deprecated with no replacement.voidsetRenderer(Class renderedClass, ObjectRenderer renderer) Used by subclasses to add a renderer to the hierarchy passed as parameter.voidsetThreshold(String levelStr) The string form ofsetThreshold(Level).voidsetThreshold(Level level) Enable logging for logging requests with levellor higher.voidsetThrowableRenderer(ThrowableRenderer throwableRenderer) Set throwable renderer.voidshutdown()Shutting down a hierarchy will safely close and remove all appenders in all categories including the root logger.voidshutdown(ClassLoader classLoader) (package private) voidshutdown(LoggerContext context) private final voidupdateChildren(ProvisionNode pn, Logger logger) We update the links for all the children that placed themselves in the provision node 'pn'.private final voidupdateParents(Logger cat) This method loops through all the *potential* parents of 'cat'.
-
Field Details
-
LOGGER_ADAPTER
-
CONTEXT_MAP
-
defaultFactory
-
listeners
-
ht
Hashtable ht -
root
Logger root -
rendererMap
RendererMap rendererMap -
thresholdInt
int thresholdInt -
threshold
Level threshold -
emittedNoAppenderWarning
boolean emittedNoAppenderWarning -
emittedNoResourceBundleWarning
boolean emittedNoResourceBundleWarning -
throwableRenderer
-
-
Constructor Details
-
Hierarchy
Creates a new logger hierarchy.- Parameters:
root- The root of the new hierarchy.
-
-
Method Details
-
getContext
-
getInstance
-
getInstance
-
getInstance
static Logger getInstance(LoggerContext context, String name, Hierarchy.PrivateLoggerAdapter factory) -
getLoggersMap
-
getRootLogger
-
addHierarchyEventListener
Description copied from interface:LoggerRepositoryAdd aHierarchyEventListenerevent to the repository.- Specified by:
addHierarchyEventListenerin interfaceLoggerRepository- Parameters:
listener- The listener
-
addRenderer
Adds an object renderer for a specific class. -
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
- Specified by:
emitNoAppenderWarningin interfaceLoggerRepository
-
exists
Tests 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.
-
exists
-
exists
-
fireAddAppenderEvent
- Specified by:
fireAddAppenderEventin interfaceLoggerRepository
-
fireRemoveAppenderEvent
-
getContext
-
getCurrentCategories
Deprecated.Please usegetCurrentLoggers()instead.Description copied from interface:LoggerRepositoryDeprecated. Please useLoggerRepository.getCurrentLoggers()instead.- Specified by:
getCurrentCategoriesin interfaceLoggerRepository- Returns:
- an enumeration of loggers.
-
getCurrentLoggers
Gets all the currently defined categories in this hierarchy as anEnumeration.The root logger is not included in the returned
Enumeration.- Specified by:
getCurrentLoggersin interfaceLoggerRepository
-
getLogger
Gets 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
-
getLogger
Gets 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.
-
getLogger
-
getRendererMap
Gets the renderer map for this hierarchy.- Specified by:
getRendererMapin interfaceRendererSupport
-
getRootLogger
Gets the root of this hierarchy.- Specified by:
getRootLoggerin interfaceLoggerRepository- Since:
- 0.9.0
-
getRootLogger
-
getThreshold
Gets aLevelrepresentation of theenablestate.- Specified by:
getThresholdin interfaceLoggerRepository- Returns:
- the level.
- Since:
- 1.2
-
getThrowableRenderer
Get throwable renderer.- Specified by:
getThrowableRendererin interfaceThrowableRendererSupport- Returns:
- throwable renderer, may be null.
-
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- Parameters:
level- The level- Returns:
- whether this repository is disabled.
-
overrideAsNeeded
Deprecated.Deprecated with no replacement. -
resetConfiguration
public void resetConfiguration()Resets 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
-
resetConfiguration
-
resetConfiguration
-
setDisableOverride
Deprecated.Deprecated with no replacement.Does nothing. -
setRenderer
Used by subclasses to add a renderer to the hierarchy passed as parameter.- Specified by:
setRendererin interfaceRendererSupport
-
setThreshold
Enable logging for logging requests with levellor higher. By default all levels are enabled.- Specified by:
setThresholdin interfaceLoggerRepository- Parameters:
level- The minimum level for which logging requests are sent to their appenders.
-
setThreshold
The string form ofsetThreshold(Level).- Specified by:
setThresholdin interfaceLoggerRepository- Parameters:
levelStr- The threshold value
-
setThrowableRenderer
Set throwable renderer.- Specified by:
setThrowableRendererin interfaceThrowableRendererSupport- Parameters:
throwableRenderer- 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
andinvalid reference
org.apache.log4j.net.SocketAppenderAsyncAppenderneed 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
-
shutdown
-
shutdown
-
updateChildren
We update the links for all the children that placed themselves in the provision node 'pn'. The second argument 'cat' is a reference for the newly created Logger, parent of all the children in 'pn' We loop on all the children 'c' in 'pn': If the child 'c' has been already linked to a child of 'cat' then there is no need to update 'c'. Otherwise, we set cat's parent field to c's parent and set c's parent field to cat. -
updateParents
This method loops through all the *potential* parents of 'cat'. There 3 possible cases: 1) No entry for the potential parent of 'cat' exists We create a ProvisionNode for this potential parent and insert 'cat' in that provision node. 2) There entry is of type Logger for the potential parent. The entry is 'cat's nearest existing parent. We update cat's parent field with this entry. We also break from the loop because updating our parent's parent is our parent's responsibility. 3) There entry is of type ProvisionNode for this potential parent. We add 'cat' to the list of children for this potential parent.
-
getCurrentLoggers()instead.