Log4j 1.3alpha-7

org.apache.log4j
Class Hierarchy

java.lang.Object
  extended byorg.apache.log4j.Hierarchy
All Implemented Interfaces:
LoggerRepository, RendererSupport

public class Hierarchy
extends Object
implements LoggerRepository, RendererSupport

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ü, Mark Womack

Constructor Summary
Hierarchy(Logger root)
          Create a new logger hierarchy.
 
Method Summary
 void addErrorItem(ErrorItem errorItem)
          Add an error item to the list of previously encountered errors.
 void addLoggerEventListener(LoggerEventListener listener)
          Add a LoggerEventListener to the repository.
 void addLoggerRepositoryEventListener(LoggerRepositoryEventListener listener)
          Add a LoggerRepositoryEventListener to the repository.
 void addRenderer(Class classToRender, ObjectRenderer or)
          Add an object renderer for a specific class.
 void clear()
          This call will clear all logger definitions from the internal hashtable.
 void emitNoAppenderWarning(Logger cat)
           
 Logger exists(String name)
          Check if the named logger exists in the hierarchy.
 void fireAddAppenderEvent(Logger logger, Appender appender)
          Requests that a appender added event be sent to any registered LoggerEventListener.
 void fireConfigurationChangedEvent()
          Requests that a configuration changed event be sent to any registered LoggerRepositoryEventListener.
 void fireLevelChangedEvent(Logger logger)
          Requests that a level changed event be sent to any registered LoggerEventListener.
 void fireRemoveAppenderEvent(Logger logger, Appender appender)
          Requests that a appender removed event be sent to any registered LoggerEventListener.
 Enumeration getCurrentCategories()
          Deprecated. Please use getCurrentLoggers() instead.
 Enumeration getCurrentLoggers()
          Returns all the currently defined categories in this hierarchy as an Enumeration.
 List getErrorList()
          Return the the list of previously encoutered error items.
 Logger getLogger(String name)
          Return a new logger instance named as the first parameter using the default factory.
 Logger getLogger(String name, LoggerFactory factory)
          Return a new logger instance named as the first parameter using factory.
 String getName()
          Return the name of this hierarchy.
 Object getObject(String key)
          A LoggerRepository can also act as a store for various objects used by log4j components.
 PluginRegistry getPluginRegistry()
          Return the PluginRegisty for this LoggerRepository.
 Map getProperties()
          Get the properties specific for this repository.
 String getProperty(String key)
          Get the property of this repository.
 RendererMap getRendererMap()
          Get the renderer map for this hierarchy.
 Logger getRootLogger()
          Get the root of this hierarchy.
 org.apache.log4j.scheduler.Scheduler getScheduler()
          Return this repository's own scheduler.
 Level getThreshold()
          Returns a Level representation of the enable state.
 boolean isDisabled(int level)
          This method will return true if this repository is disabled for level object passed as parameter and false otherwise.
 boolean isPristine()
          Is the current configuration of the reposiroty in its original (pristine) state?
 void putObject(String key, Object value)
          Store an object under 'key'.
 void removeLoggerEventListener(LoggerEventListener listener)
          Remove a LoggerEventListener from the repository.
 void removeLoggerRepositoryEventListener(LoggerRepositoryEventListener listener)
          Remove a LoggerRepositoryEventListener from the repository.
 void resetConfiguration()
          Reset all values contained in this hierarchy instance to their default.
 void setName(String repoName)
          A logger repository is a named entity.
 void setPristine(boolean state)
          Set the pristine flag.
 void setProperty(String key, String value)
          Set a property of this repository.
 void setRenderer(Class renderedClass, ObjectRenderer renderer)
          Used by subclasses to add a renderer to the hierarchy passed as parameter.
 void setThreshold(Level l)
          Enable logging for logging requests with level l or higher.
 void setThreshold(String levelStr)
          The string form of setThreshold(Level).
 void shutdown()
          Shutting down a hierarchy will safely close and remove all appenders in all categories including the root logger.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

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(Class classToRender,
                        ObjectRenderer or)
Add an object renderer for a specific class.


addLoggerRepositoryEventListener

public void addLoggerRepositoryEventListener(LoggerRepositoryEventListener listener)
Add a LoggerRepositoryEventListener to the repository. The listener will be called when repository events occur.

Specified by:
addLoggerRepositoryEventListener in interface LoggerRepository
Since:
1.3

removeLoggerRepositoryEventListener

public void removeLoggerRepositoryEventListener(LoggerRepositoryEventListener listener)
Remove a LoggerRepositoryEventListener from the repository.

Specified by:
removeLoggerRepositoryEventListener in interface LoggerRepository
Since:
1.3

addLoggerEventListener

public void addLoggerEventListener(LoggerEventListener listener)
Add a LoggerEventListener to the repository. The listener will be called when repository events occur.

Specified by:
addLoggerEventListener in interface LoggerRepository
Since:
1.3

removeLoggerEventListener

public void removeLoggerEventListener(LoggerEventListener listener)
Remove a LoggerEventListener from the repository.

Specified by:
removeLoggerEventListener in interface LoggerRepository
Since:
1.3

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(Logger cat)
Specified by:
emitNoAppenderWarning in interface LoggerRepository

exists

public Logger exists(String name)
Check if the named logger exists in the hierarchy. If so return its reference, otherwise returns null.

Specified by:
exists in interface LoggerRepository
Parameters:
name - The name of the logger to search for.

getName

public String getName()
Return the name of this hierarchy.

Specified by:
getName in interface LoggerRepository

setName

public void setName(String repoName)
Description copied from interface: LoggerRepository
A logger repository is a named entity.

Specified by:
setName in interface LoggerRepository

getProperties

public Map getProperties()
Description copied from interface: LoggerRepository
Get the properties specific for this repository.

Specified by:
getProperties in interface LoggerRepository

getProperty

public String getProperty(String key)
Description copied from interface: LoggerRepository
Get the property of this repository.

Specified by:
getProperty in interface LoggerRepository

setProperty

public void setProperty(String key,
                        String value)
Description copied from interface: LoggerRepository
Set a property of this repository.

Specified by:
setProperty in interface LoggerRepository

setThreshold

public void setThreshold(String levelStr)
The string form of setThreshold(Level).

Specified by:
setThreshold in interface LoggerRepository

setThreshold

public void setThreshold(Level l)
Enable logging for logging requests with level l or higher. By default all levels are enabled.

Specified by:
setThreshold in interface LoggerRepository
Parameters:
l - The minimum level for which logging requests are sent to their appenders.

getPluginRegistry

public PluginRegistry getPluginRegistry()
Description copied from interface: LoggerRepository
Return the PluginRegisty for this LoggerRepository.

Specified by:
getPluginRegistry in interface LoggerRepository

fireAddAppenderEvent

public void fireAddAppenderEvent(Logger logger,
                                 Appender appender)
Requests that a appender added event be sent to any registered LoggerEventListener.

Specified by:
fireAddAppenderEvent in interface LoggerRepository
Parameters:
logger - The logger to which the appender was added.
appender - The appender added to the logger.
Since:
1.3

fireRemoveAppenderEvent

public void fireRemoveAppenderEvent(Logger logger,
                                    Appender appender)
Requests that a appender removed event be sent to any registered LoggerEventListener.

Specified by:
fireRemoveAppenderEvent in interface LoggerRepository
Parameters:
logger - The logger from which the appender was removed.
appender - The appender removed from the logger.
Since:
1.3

fireLevelChangedEvent

public void fireLevelChangedEvent(Logger logger)
Requests that a level changed event be sent to any registered LoggerEventListener.

Specified by:
fireLevelChangedEvent in interface LoggerRepository
Parameters:
logger - The logger which changed levels.
Since:
1.3

fireConfigurationChangedEvent

public void fireConfigurationChangedEvent()
Requests that a configuration changed event be sent to any registered LoggerRepositoryEventListener.

Specified by:
fireConfigurationChangedEvent in interface LoggerRepository
Since:
1.3

getThreshold

public Level getThreshold()
Returns a Level representation of the enable state.

Specified by:
getThreshold in interface LoggerRepository
Since:
1.2

getLogger

public Logger getLogger(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:
getLogger in interface LoggerRepository
Parameters:
name - The name of the logger to retrieve.

getLogger

public Logger getLogger(String name,
                        LoggerFactory factory)
Return a new logger instance named as the first parameter using factory.

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 interface LoggerRepository
Parameters:
name - The name of the logger to retrieve.
factory - The factory that will make the new logger instance.

getCurrentLoggers

public Enumeration getCurrentLoggers()
Returns all the currently defined categories in this hierarchy as an Enumeration.

The root logger is not included in the returned Enumeration.

Specified by:
getCurrentLoggers in interface LoggerRepository

getErrorList

public List getErrorList()
Return the the list of previously encoutered error items.

Specified by:
getErrorList in interface LoggerRepository
Returns:
List

addErrorItem

public void addErrorItem(ErrorItem errorItem)
Add an error item to the list of previously encountered errors.

Specified by:
addErrorItem in interface LoggerRepository
Parameters:
errorItem - an ErrorItem to add to the error list
Since:
1.3

getCurrentCategories

public Enumeration getCurrentCategories()
Deprecated. Please use getCurrentLoggers() instead.

Specified by:
getCurrentCategories in interface LoggerRepository

getRendererMap

public RendererMap getRendererMap()
Get the renderer map for this hierarchy.

Specified by:
getRendererMap in interface RendererSupport

getRootLogger

public Logger getRootLogger()
Get the root of this hierarchy.

Specified by:
getRootLogger in interface LoggerRepository
Since:
0.9.0

isDisabled

public boolean isDisabled(int level)
This method will return true if this repository is disabled for level object passed as parameter and false otherwise. See also the threshold emthod.

Specified by:
isDisabled in interface LoggerRepository

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 to null, sets their additivity flag to true 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 interface LoggerRepository
Since:
0.8.5

setRenderer

public void setRenderer(Class renderedClass,
                        ObjectRenderer renderer)
Used by subclasses to add a renderer to the hierarchy passed as parameter.

Specified by:
setRenderer in interface RendererSupport

isPristine

public boolean isPristine()
Description copied from interface: LoggerRepository
Is the current configuration of the reposiroty in its original (pristine) state?

Specified by:
isPristine in interface LoggerRepository

setPristine

public void setPristine(boolean state)
Description copied from interface: LoggerRepository
Set the pristine flag.

Specified by:
setPristine in interface LoggerRepository
See Also:
LoggerRepository.isPristine()

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 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 interface LoggerRepository
Since:
1.0

getScheduler

public org.apache.log4j.scheduler.Scheduler getScheduler()
Return this repository's own scheduler. The scheduler is lazily instantiated.

Specified by:
getScheduler in interface LoggerRepository
Returns:
this repository's own scheduler.

putObject

public void putObject(String key,
                      Object value)
Description copied from interface: LoggerRepository
Store an object under 'key'. If no object can be found, null is returned.

Specified by:
putObject in interface LoggerRepository
Parameters:
key -
value -

getObject

public Object getObject(String key)
Description copied from interface: LoggerRepository
A LoggerRepository can also act as a store for various objects used by log4j components.

Specified by:
getObject in interface LoggerRepository
Returns:
The object stored under 'key'.

Log4j 1.3alpha-7

Copyright 2000-2005 Apache Software Foundation.