Class LoggerRepositoryExImpl
- All Implemented Interfaces:
org.apache.log4j.spi.LoggerRepository
,LoggerRepositoryEx
,org.apache.log4j.spi.RendererSupport
,org.apache.log4j.xml.UnrecognizedElementHandler
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static final class
Proxy that implements HierarchyEventListener and delegates to LoggerEventListener.private static final class
Implementation of RendererSupportImpl if not provided by LoggerRepository. -
Field Summary
FieldsModifier and TypeFieldDescriptionError list.Map of HierarchyEventListener keyed by LoggingEventListener.private org.apache.log4j.spi.LoggerFactory
Logger factory.private String
Name of hierarchy.The repository can also be used as an object store for various objects used by log4j components.private PluginRegistry
Plug in registry.private boolean
True if hierarchy has not been modified.Properties.private final org.apache.log4j.spi.RendererSupport
Renderer support.private final org.apache.log4j.spi.LoggerRepository
Wrapped logger repository.private final ArrayList<LoggerRepositoryEventListener>
List of repository event listeners.private Scheduler
Scheduler. -
Constructor Summary
ConstructorsConstructorDescriptionLoggerRepositoryExImpl
(org.apache.log4j.spi.LoggerRepository repository) Constructs a new logger hierarchy. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addErrorItem
(ErrorItem errorItem) Add an error item to the list of previously encountered errors.void
addHierarchyEventListener
(org.apache.log4j.spi.HierarchyEventListener listener) Deprecated.Superceded by addLoggerEventListenervoid
addLoggerEventListener
(LoggerEventListener listener) Add aLoggerEventListener
to the repository.void
Add aLoggerRepositoryEventListener
to the repository.void
emitNoAppenderWarning
(org.apache.log4j.Category cat) Issue warning that there are no appenders in hierarchy.org.apache.log4j.Logger
Check if the named logger exists in the hierarchy.void
fireAddAppenderEvent
(org.apache.log4j.Category logger, org.apache.log4j.Appender appender) Requests that a appender added event be sent to any registeredLoggerEventListener
.void
Requests that a configuration changed event be sent to any registeredLoggerRepositoryEventListener
.void
fireLevelChangedEvent
(org.apache.log4j.Logger logger) Requests that a level changed event be sent to any registeredLoggerEventListener
.void
fireRemoveAppenderEvent
(org.apache.log4j.Category logger, org.apache.log4j.Appender appender) Requests that a appender removed event be sent to any registeredLoggerEventListener
.Deprecated.Please usegetCurrentLoggers()
instead.Returns all the currently defined categories in this hierarchy as anEnumeration
.Return the the list of previously encouterederror items
.org.apache.log4j.Logger
Return a new logger instance named as the first parameter using the default factory.org.apache.log4j.Logger
Return a new logger instance named as the first parameter usingfactory
.org.apache.log4j.spi.LoggerFactory
Get logger factory.getName()
Return the name of this hierarchy.Get object by key.Return the PluginRegisty for this LoggerRepository.Get the properties specific for this repository.getProperty
(String key) Get the property of this repository.org.apache.log4j.or.RendererMap
Get the renderer map for this hierarchy.org.apache.log4j.Logger
Get the root of this hierarchy.Return this repository's own scheduler.org.apache.log4j.Level
Returns the current threshold.boolean
isDisabled
(int level) This method will returntrue
if this repository is disabled forlevel
value passed as parameter andfalse
otherwise.boolean
Is the current configuration of the repository in its original (pristine) state?boolean
parseUnrecognizedElement
(Element element, Properties props) void
Puts object by key.void
removeLoggerEventListener
(LoggerEventListener listener) Remove aLoggerEventListener
from the repository.void
Remove aLoggerRepositoryEventListener
from the repository.void
Reset all values contained in this hierarchy instance to their default.void
setLoggerFactory
(org.apache.log4j.spi.LoggerFactory factory) Set logger factory.void
Set the name of this repository.void
setPristine
(boolean state) Set the pristine flag.void
setProperty
(String key, String value) Set a property by key and value.void
setRenderer
(Class renderedClass, org.apache.log4j.or.ObjectRenderer renderer) Used by subclasses to add a renderer to the hierarchy passed as parameter.void
setThreshold
(String levelStr) The string form ofsetThreshold(Level)
.void
setThreshold
(org.apache.log4j.Level l) Enable logging for logging requests with levell
or higher.void
shutdown()
Shutting down a hierarchy will safely close and remove all appenders in all categories including the root logger.
-
Field Details
-
repo
private final org.apache.log4j.spi.LoggerRepository repoWrapped logger repository. -
loggerFactory
private org.apache.log4j.spi.LoggerFactory loggerFactoryLogger factory. Does not affect class of logger created by underlying repository. -
rendererSupport
private final org.apache.log4j.spi.RendererSupport rendererSupportRenderer support. -
repositoryEventListeners
List of repository event listeners. -
loggerEventListeners
private final Map<LoggerEventListener,LoggerRepositoryExImpl.HierarchyEventListenerProxy> loggerEventListenersMap of HierarchyEventListener keyed by LoggingEventListener. -
name
Name of hierarchy. -
pluginRegistry
Plug in registry. -
properties
Properties. -
scheduler
Scheduler. -
objectMap
The repository can also be used as an object store for various objects used by log4j components. -
errorList
Error list. -
pristine
private boolean pristineTrue if hierarchy has not been modified.
-
-
Constructor Details
-
LoggerRepositoryExImpl
public LoggerRepositoryExImpl(org.apache.log4j.spi.LoggerRepository repository) Constructs a new logger hierarchy.- Parameters:
repository
- Base implementation of repository.
-
-
Method Details
-
addLoggerRepositoryEventListener
Add aLoggerRepositoryEventListener
to the repository. The listener will be called when repository events occur.- Specified by:
addLoggerRepositoryEventListener
in interfaceLoggerRepositoryEx
- Parameters:
listener
- listener
-
removeLoggerRepositoryEventListener
Remove aLoggerRepositoryEventListener
from the repository.- Specified by:
removeLoggerRepositoryEventListener
in interfaceLoggerRepositoryEx
- Parameters:
listener
- listener
-
addLoggerEventListener
Add aLoggerEventListener
to the repository. The listener will be called when repository events occur.- Specified by:
addLoggerEventListener
in interfaceLoggerRepositoryEx
- Parameters:
listener
- listener
-
addHierarchyEventListener
public void addHierarchyEventListener(org.apache.log4j.spi.HierarchyEventListener listener) Deprecated.Superceded by addLoggerEventListenerAdd aHierarchyEventListener
event to the repository.- Specified by:
addHierarchyEventListener
in interfaceorg.apache.log4j.spi.LoggerRepository
- Parameters:
listener
- listener
-
removeLoggerEventListener
Remove aLoggerEventListener
from the repository.- Specified by:
removeLoggerEventListener
in interfaceLoggerRepositoryEx
- Parameters:
listener
- listener to be removed
-
emitNoAppenderWarning
public void emitNoAppenderWarning(org.apache.log4j.Category cat) Issue warning that there are no appenders in hierarchy.- Specified by:
emitNoAppenderWarning
in interfaceorg.apache.log4j.spi.LoggerRepository
- Parameters:
cat
- logger, not currently used.
-
exists
Check if the named logger exists in the hierarchy. If so return its reference, otherwise returnsnull
.- Specified by:
exists
in interfaceorg.apache.log4j.spi.LoggerRepository
- Parameters:
loggerName
- The name of the logger to search for.- Returns:
- true if logger exists.
-
getName
Return the name of this hierarchy.- Specified by:
getName
in interfaceLoggerRepositoryEx
- Returns:
- name of hierarchy
-
setName
Set the name of this repository.Note that once named, a repository cannot be rerenamed.
- Specified by:
setName
in interfaceLoggerRepositoryEx
- Parameters:
repoName
- name of hierarchy
-
getProperties
Get the properties specific for this repository.- Specified by:
getProperties
in interfaceLoggerRepositoryEx
- Returns:
- property map.
-
getProperty
Get the property of this repository.- Specified by:
getProperty
in interfaceLoggerRepositoryEx
- Parameters:
key
- property key.- Returns:
- key value or null if not set.
-
setProperty
Set a property by key and value. The property will be shared by all events in this repository.- Specified by:
setProperty
in interfaceLoggerRepositoryEx
- Parameters:
key
- property namevalue
- property value
-
setThreshold
The string form ofsetThreshold(Level)
.- Specified by:
setThreshold
in interfaceorg.apache.log4j.spi.LoggerRepository
- Parameters:
levelStr
- symbolic name for level
-
setThreshold
public void setThreshold(org.apache.log4j.Level l) Enable logging for logging requests with levell
or higher. By default all levels are enabled.- Specified by:
setThreshold
in interfaceorg.apache.log4j.spi.LoggerRepository
- Parameters:
l
- The minimum level for which logging requests are sent to their appenders.
-
getPluginRegistry
Return the PluginRegisty for this LoggerRepository.- Specified by:
getPluginRegistry
in interfaceLoggerRepositoryEx
- Returns:
- plug in registry.
-
fireAddAppenderEvent
public void fireAddAppenderEvent(org.apache.log4j.Category logger, org.apache.log4j.Appender appender) Requests that a appender added event be sent to any registeredLoggerEventListener
.- Specified by:
fireAddAppenderEvent
in interfaceorg.apache.log4j.spi.LoggerRepository
- Parameters:
logger
- The logger to which the appender was added.appender
- The appender added to the logger.
-
fireRemoveAppenderEvent
public void fireRemoveAppenderEvent(org.apache.log4j.Category logger, org.apache.log4j.Appender appender) Requests that a appender removed event be sent to any registeredLoggerEventListener
.- Specified by:
fireRemoveAppenderEvent
in interfaceLoggerRepositoryEx
- Parameters:
logger
- The logger from which the appender was removed.appender
- The appender removed from the logger.
-
fireLevelChangedEvent
public void fireLevelChangedEvent(org.apache.log4j.Logger logger) Requests that a level changed event be sent to any registeredLoggerEventListener
.- Specified by:
fireLevelChangedEvent
in interfaceLoggerRepositoryEx
- Parameters:
logger
- The logger which changed levels.
-
fireConfigurationChangedEvent
public void fireConfigurationChangedEvent()Requests that a configuration changed event be sent to any registeredLoggerRepositoryEventListener
.- Specified by:
fireConfigurationChangedEvent
in interfaceLoggerRepositoryEx
-
getThreshold
public org.apache.log4j.Level getThreshold()Returns the current threshold.- Specified by:
getThreshold
in interfaceorg.apache.log4j.spi.LoggerRepository
- Returns:
- current threshold level
- Since:
- 1.2
-
getLogger
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:
getLogger
in interfaceorg.apache.log4j.spi.LoggerRepository
- Parameters:
loggerName
- The name of the logger to retrieve.- Returns:
- logger
-
getLogger
public org.apache.log4j.Logger getLogger(String loggerName, org.apache.log4j.spi.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
factory
parameter and linked with its existing ancestors as well as children.- Specified by:
getLogger
in interfaceorg.apache.log4j.spi.LoggerRepository
- Parameters:
loggerName
- The name of the logger to retrieve.factory
- The factory that will make the new logger instance.- Returns:
- logger
-
getCurrentLoggers
Returns all the currently defined categories in this hierarchy as anEnumeration
.The root logger is not included in the returned
Enumeration
.- Specified by:
getCurrentLoggers
in interfaceorg.apache.log4j.spi.LoggerRepository
- Returns:
- enumerator of current loggers
-
getErrorList
Return the the list of previously encouterederror items
.- Specified by:
getErrorList
in interfaceLoggerRepositoryEx
- Returns:
- list of errors
-
addErrorItem
Add an error item to the list of previously encountered errors.- Specified by:
addErrorItem
in interfaceLoggerRepositoryEx
- Parameters:
errorItem
- error to add to list of errors.
-
getCurrentCategories
Deprecated.Please usegetCurrentLoggers()
instead.Get enumerator over current loggers.- Specified by:
getCurrentCategories
in interfaceorg.apache.log4j.spi.LoggerRepository
- Returns:
- enumerator over current loggers
-
getRendererMap
public org.apache.log4j.or.RendererMap getRendererMap()Get the renderer map for this hierarchy.- Specified by:
getRendererMap
in interfaceorg.apache.log4j.spi.RendererSupport
- Returns:
- renderer map
-
getRootLogger
public org.apache.log4j.Logger getRootLogger()Get the root of this hierarchy.- Specified by:
getRootLogger
in interfaceorg.apache.log4j.spi.LoggerRepository
- Returns:
- root of hierarchy
- Since:
- 0.9.0
-
isDisabled
public boolean isDisabled(int level) This method will returntrue
if this repository is disabled forlevel
value passed as parameter andfalse
otherwise. See also thethreshold
method.- Specified by:
isDisabled
in interfaceorg.apache.log4j.spi.LoggerRepository
- Parameters:
level
- numeric value for level.- Returns:
- true if disabled for specified level
-
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 totrue
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.
- Specified by:
resetConfiguration
in interfaceorg.apache.log4j.spi.LoggerRepository
- Since:
- 0.8.5
-
setRenderer
Used by subclasses to add a renderer to the hierarchy passed as parameter.- Specified by:
setRenderer
in interfaceorg.apache.log4j.spi.RendererSupport
- Parameters:
renderedClass
- classrenderer
- object used to render class.
-
isPristine
public boolean isPristine()Is the current configuration of the repository in its original (pristine) state?- Specified by:
isPristine
in interfaceLoggerRepositoryEx
- Returns:
- true if repository is in original state.
-
setPristine
public void setPristine(boolean state) Set the pristine flag.- Specified by:
setPristine
in interfaceLoggerRepositoryEx
- Parameters:
state
- state- See Also:
-
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 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.- Specified by:
shutdown
in interfaceorg.apache.log4j.spi.LoggerRepository
- Since:
- 1.0
-
getScheduler
Return this repository's own scheduler. The scheduler is lazily instantiated.- Specified by:
getScheduler
in interfaceLoggerRepositoryEx
- Returns:
- this repository's own scheduler.
-
putObject
Puts object by key.- Specified by:
putObject
in interfaceLoggerRepositoryEx
- Parameters:
key
- key, may not be null.value
- object to associate with key.
-
getObject
Get object by key.- Specified by:
getObject
in interfaceLoggerRepositoryEx
- Parameters:
key
- key, may not be null.- Returns:
- object associated with key or null.
-
setLoggerFactory
public void setLoggerFactory(org.apache.log4j.spi.LoggerFactory factory) Set logger factory.- Specified by:
setLoggerFactory
in interfaceLoggerRepositoryEx
- Parameters:
factory
- logger factory.
-
getLoggerFactory
public org.apache.log4j.spi.LoggerFactory getLoggerFactory()Get logger factory.- Specified by:
getLoggerFactory
in interfaceLoggerRepositoryEx
- Returns:
- logger factory.
-
parseUnrecognizedElement
- Specified by:
parseUnrecognizedElement
in interfaceorg.apache.log4j.xml.UnrecognizedElementHandler
- Throws:
Exception
-