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.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
Hierarchy.PrivateLoggerAdapter
private static class
Hierarchy.PrivateLogManager
Private LogManager.
-
Field Summary
Fields Modifier and Type Field Description private static java.util.WeakHashMap<LoggerContext,java.util.concurrent.ConcurrentMap<java.lang.String,Logger>>
CONTEXT_MAP
private LoggerFactory
defaultFactory
(package private) boolean
emittedNoAppenderWarning
(package private) boolean
emittedNoResourceBundleWarning
(package private) java.util.Hashtable
ht
private java.util.Vector
listeners
private static Hierarchy.PrivateLoggerAdapter
LOGGER_ADAPTER
(package private) RendererMap
rendererMap
(package private) Logger
root
(package private) Level
threshold
(package private) int
thresholdInt
private ThrowableRenderer
throwableRenderer
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description void
addHierarchyEventListener(HierarchyEventListener listener)
Add aHierarchyEventListener
event to the repository.void
addRenderer(java.lang.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(java.lang.String name)
Tests if the named logger exists in the hierarchy.(package private) Logger
exists(java.lang.String name, java.lang.ClassLoader classLoader)
(package private) Logger
exists(java.lang.String name, LoggerContext loggerContext)
void
fireAddAppenderEvent(Category logger, Appender appender)
(package private) void
fireRemoveAppenderEvent(Category logger, Appender appender)
(package private) static LoggerContext
getContext()
(package private) LoggerContext
getContext(java.lang.ClassLoader classLoader)
java.util.Enumeration
getCurrentCategories()
Deprecated.Please usegetCurrentLoggers()
instead.java.util.Enumeration
getCurrentLoggers()
Gets all the currently defined categories in this hierarchy as anEnumeration
.private Logger
getInstance(LoggerContext context, java.lang.String name)
private Logger
getInstance(LoggerContext context, java.lang.String name, Hierarchy.PrivateLoggerAdapter factory)
private Logger
getInstance(LoggerContext context, java.lang.String name, LoggerFactory factory)
Logger
getLogger(java.lang.String name)
Gets a new logger instance named as the first parameter using the default factory.(package private) Logger
getLogger(java.lang.String name, java.lang.ClassLoader classLoader)
Logger
getLogger(java.lang.String name, LoggerFactory factory)
Gets a new logger instance named as the first parameter usingfactory
.(package private) Logger
getLogger(java.lang.String name, LoggerFactory factory, java.lang.ClassLoader classLoader)
(package private) static java.util.concurrent.ConcurrentMap<java.lang.String,Logger>
getLoggersMap(LoggerContext context)
RendererMap
getRendererMap()
Gets the renderer map for this hierarchy.Logger
getRootLogger()
Gets the root of this hierarchy.(package private) Logger
getRootLogger(java.lang.ClassLoader classLoader)
Level
getThreshold()
Gets aLevel
representation of theenable
state.ThrowableRenderer
getThrowableRenderer()
Get throwable renderer.boolean
isDisabled(int level)
This method will returntrue
if this repository is disabled forlevel
object passed as parameter andfalse
otherwise.void
overrideAsNeeded(java.lang.String override)
Deprecated.Deprecated with no replacement.void
resetConfiguration()
Resets all values contained in this hierarchy instance to their default.(package private) void
resetConfiguration(java.lang.ClassLoader classLoader)
(package private) void
resetConfiguration(LoggerContext loggerContext)
void
setDisableOverride(java.lang.String override)
Deprecated.Deprecated with no replacement.void
setRenderer(java.lang.Class renderedClass, ObjectRenderer renderer)
Used by subclasses to add a renderer to the hierarchy passed as parameter.void
setThreshold(java.lang.String levelStr)
The string form ofsetThreshold(Level)
.void
setThreshold(Level level)
Enable logging for logging requests with levell
or higher.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(java.lang.ClassLoader classLoader)
(package private) void
shutdown(LoggerContext context)
-
-
-
Field Detail
-
LOGGER_ADAPTER
private static final Hierarchy.PrivateLoggerAdapter LOGGER_ADAPTER
-
CONTEXT_MAP
private static final java.util.WeakHashMap<LoggerContext,java.util.concurrent.ConcurrentMap<java.lang.String,Logger>> CONTEXT_MAP
-
defaultFactory
private final LoggerFactory defaultFactory
-
listeners
private final java.util.Vector listeners
-
ht
java.util.Hashtable ht
-
root
Logger root
-
rendererMap
RendererMap rendererMap
-
thresholdInt
int thresholdInt
-
threshold
Level threshold
-
emittedNoAppenderWarning
boolean emittedNoAppenderWarning
-
emittedNoResourceBundleWarning
boolean emittedNoResourceBundleWarning
-
throwableRenderer
private ThrowableRenderer throwableRenderer
-
-
Constructor Detail
-
Hierarchy
public Hierarchy(Logger root)
Creates a new logger hierarchy.- Parameters:
root
- The root of the new hierarchy.
-
-
Method Detail
-
getContext
static LoggerContext getContext()
-
getInstance
private Logger getInstance(LoggerContext context, java.lang.String name)
-
getInstance
private Logger getInstance(LoggerContext context, java.lang.String name, LoggerFactory factory)
-
getInstance
private Logger getInstance(LoggerContext context, java.lang.String name, Hierarchy.PrivateLoggerAdapter factory)
-
getLoggersMap
static java.util.concurrent.ConcurrentMap<java.lang.String,Logger> getLoggersMap(LoggerContext context)
-
addHierarchyEventListener
public void addHierarchyEventListener(HierarchyEventListener listener)
Description copied from interface:LoggerRepository
Add aHierarchyEventListener
event to the repository.- Specified by:
addHierarchyEventListener
in interfaceLoggerRepository
- Parameters:
listener
- The listener
-
addRenderer
public void addRenderer(java.lang.Class classToRender, ObjectRenderer or)
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
public void emitNoAppenderWarning(Category cat)
- Specified by:
emitNoAppenderWarning
in interfaceLoggerRepository
-
exists
public Logger exists(java.lang.String name)
Tests if the named logger exists in the hierarchy. If so return its reference, otherwise returnsnull
.- Specified by:
exists
in interfaceLoggerRepository
- Parameters:
name
- The name of the logger to search for.
-
exists
Logger exists(java.lang.String name, java.lang.ClassLoader classLoader)
-
exists
Logger exists(java.lang.String name, LoggerContext loggerContext)
-
fireAddAppenderEvent
public void fireAddAppenderEvent(Category logger, Appender appender)
- Specified by:
fireAddAppenderEvent
in interfaceLoggerRepository
-
getContext
LoggerContext getContext(java.lang.ClassLoader classLoader)
-
getCurrentCategories
@Deprecated public java.util.Enumeration getCurrentCategories()
Deprecated.Please usegetCurrentLoggers()
instead.Description copied from interface:LoggerRepository
Deprecated. Please useLoggerRepository.getCurrentLoggers()
instead.- Specified by:
getCurrentCategories
in interfaceLoggerRepository
- Returns:
- an enumeration of loggers.
-
getCurrentLoggers
public java.util.Enumeration getCurrentLoggers()
Gets all the currently defined categories in this hierarchy as anEnumeration
.The root logger is not included in the returned
Enumeration
.- Specified by:
getCurrentLoggers
in interfaceLoggerRepository
-
getLogger
public Logger getLogger(java.lang.String name)
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:
getLogger
in interfaceLoggerRepository
- Parameters:
name
- The name of the logger to retrieve.
-
getLogger
Logger getLogger(java.lang.String name, java.lang.ClassLoader classLoader)
-
getLogger
public Logger getLogger(java.lang.String name, LoggerFactory factory)
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
factory
parameter and linked with its existing ancestors as well as children.- Specified by:
getLogger
in interfaceLoggerRepository
- Parameters:
name
- The name of the logger to retrieve.factory
- The factory that will make the new logger instance.
-
getLogger
Logger getLogger(java.lang.String name, LoggerFactory factory, java.lang.ClassLoader classLoader)
-
getRendererMap
public RendererMap getRendererMap()
Gets the renderer map for this hierarchy.- Specified by:
getRendererMap
in interfaceRendererSupport
-
getRootLogger
public Logger getRootLogger()
Gets the root of this hierarchy.- Specified by:
getRootLogger
in interfaceLoggerRepository
- Since:
- 0.9.0
-
getRootLogger
Logger getRootLogger(java.lang.ClassLoader classLoader)
-
getThreshold
public Level getThreshold()
Gets aLevel
representation of theenable
state.- Specified by:
getThreshold
in interfaceLoggerRepository
- Returns:
- the level.
- Since:
- 1.2
-
getThrowableRenderer
public ThrowableRenderer getThrowableRenderer()
Get throwable renderer.- Specified by:
getThrowableRenderer
in interfaceThrowableRendererSupport
- Returns:
- throwable renderer, may be null.
-
isDisabled
public boolean isDisabled(int level)
This method will returntrue
if this repository is disabled forlevel
object passed as parameter andfalse
otherwise. See also thethreshold
emthod.- Specified by:
isDisabled
in interfaceLoggerRepository
- Parameters:
level
- The level- Returns:
- whether this repository is disabled.
-
overrideAsNeeded
@Deprecated public void overrideAsNeeded(java.lang.String override)
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 totrue
and 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:
resetConfiguration
in interfaceLoggerRepository
- Since:
- 0.8.5
-
resetConfiguration
void resetConfiguration(java.lang.ClassLoader classLoader)
-
resetConfiguration
void resetConfiguration(LoggerContext loggerContext)
-
setDisableOverride
@Deprecated 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:
setRenderer
in interfaceRendererSupport
-
setThreshold
public void setThreshold(Level level)
Enable logging for logging requests with levell
or higher. By default all levels are enabled.- Specified by:
setThreshold
in interfaceLoggerRepository
- Parameters:
level
- The minimum level for which logging requests are sent to their appenders.
-
setThreshold
public void setThreshold(java.lang.String levelStr)
The string form ofsetThreshold(Level)
.- Specified by:
setThreshold
in interfaceLoggerRepository
- Parameters:
levelStr
- The threshold value
-
setThrowableRenderer
public void setThrowableRenderer(ThrowableRenderer throwableRenderer)
Set throwable renderer.- Specified by:
setThrowableRenderer
in 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
org.apache.log4j.net.SocketAppender
andAsyncAppender
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.- Specified by:
shutdown
in interfaceLoggerRepository
- Since:
- 1.0
-
shutdown
public void shutdown(java.lang.ClassLoader classLoader)
-
shutdown
void shutdown(LoggerContext context)
-
-