org.apache.log4j

## Class LoggerRepositoryExImpl

- java.lang.Object
- - org.apache.log4j.LoggerRepositoryExImpl

- All Implemented Interfaces:
    LoggerRepositoryEx, org.apache.log4j.spi.LoggerRepository, org.apache.log4j.spi.RendererSupport, org.apache.log4j.xml.UnrecognizedElementHandler

      public final class LoggerRepositoryExImpl
      extends Object
      implements LoggerRepositoryEx, org.apache.log4j.spi.RendererSupport, org.apache.log4j.xml.UnrecognizedElementHandler

  This class implements LoggerRepositoryEx by wrapping an existing LoggerRepository implementation and implementing the newly added capabilities.

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `LoggerRepositoryExImpl(org.apache.log4j.spi.LoggerRepository repository)` Constructs a new logger hierarchy.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `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 addLoggerEventListener
    `void` | `addLoggerEventListener(LoggerEventListener listener)` Add a `LoggerEventListener` to the repository.
    `void` | `addLoggerRepositoryEventListener(LoggerRepositoryEventListener listener)` Add a `LoggerRepositoryEventListener` to the repository.
    `void` | `emitNoAppenderWarning(org.apache.log4j.Category cat)` Issue warning that there are no appenders in hierarchy.
    `org.apache.log4j.Logger` | `exists(String loggerName)` 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 registered `LoggerEventListener`.
    `void` | `fireConfigurationChangedEvent()` Requests that a configuration changed event be sent to any registered `LoggerRepositoryEventListener`.
    `void` | `fireLevelChangedEvent(org.apache.log4j.Logger logger)` Requests that a level changed event be sent to any registered `LoggerEventListener`.
    `void` | `fireRemoveAppenderEvent(org.apache.log4j.Category logger, org.apache.log4j.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`.
    `org.apache.log4j.Logger` | `getLogger(String loggerName)` Return a new logger instance named as the first parameter using the default factory.
    `org.apache.log4j.Logger` | `getLogger(String loggerName, org.apache.log4j.spi.LoggerFactory factory)` Return a new logger instance named as the first parameter using `factory`.
    `org.apache.log4j.spi.LoggerFactory` | `getLoggerFactory()` Get logger factory.
    `String` | `getName()` Return the name of this hierarchy.
    `Object` | `getObject(String key)` Get object by key.
    `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.
    `org.apache.log4j.or.RendererMap` | `getRendererMap()` Get the renderer map for this hierarchy.
    `org.apache.log4j.Logger` | `getRootLogger()` Get the root of this hierarchy.
    `Scheduler` | `getScheduler()` Return this repository's own scheduler.
    `org.apache.log4j.Level` | `getThreshold()` Returns the current threshold.
    `boolean` | `isDisabled(int level)` This method will return `true` if this repository is disabled for `level` value passed as parameter and `false` otherwise.
    `boolean` | `isPristine()` Is the current configuration of the repository in its original (pristine) state?
    `boolean` | `parseUnrecognizedElement(Element element, Properties props)`
    `void` | `putObject(String key, Object value)` Puts object by 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` | `setLoggerFactory(org.apache.log4j.spi.LoggerFactory factory)` Set logger factory.
    `void` | `setName(String repoName)` 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(org.apache.log4j.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

    - #### LoggerRepositoryExImpl

          public LoggerRepositoryExImpl(org.apache.log4j.spi.LoggerRepository repository)

      Constructs a new logger hierarchy.
      Parameters:
        `repository` - Base implementation of repository.

  - ### Method Detail

    - #### 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 `LoggerRepositoryEx`
      Parameters:
        `listener` - listener

    - #### removeLoggerRepositoryEventListener

          public void removeLoggerRepositoryEventListener(LoggerRepositoryEventListener listener)

      Remove a `LoggerRepositoryEventListener` from the repository.
      Specified by:
        `removeLoggerRepositoryEventListener` in interface `LoggerRepositoryEx`
      Parameters:
        `listener` - listener

    - #### 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 `LoggerRepositoryEx`
      Parameters:
        `listener` - listener

    - #### addHierarchyEventListener

          public void addHierarchyEventListener(org.apache.log4j.spi.HierarchyEventListener listener)

      Deprecated. Superceded by addLoggerEventListener
      Add a `HierarchyEventListener` event to the repository.
      Specified by:
        `addHierarchyEventListener` in interface `org.apache.log4j.spi.LoggerRepository`
      Parameters:
        `listener` - listener

    - #### removeLoggerEventListener

          public void removeLoggerEventListener(LoggerEventListener listener)

      Remove a `LoggerEventListener` from the repository.
      Specified by:
        `removeLoggerEventListener` in interface `LoggerRepositoryEx`
      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 interface `org.apache.log4j.spi.LoggerRepository`
      Parameters:
        `cat` - logger, not currently used.

    - #### exists

          public org.apache.log4j.Logger exists(String loggerName)

      Check if the named logger exists in the hierarchy. If so return its reference, otherwise returns `null`.
      Specified by:
        `exists` in interface `org.apache.log4j.spi.LoggerRepository`
      Parameters:
        `loggerName` - The name of the logger to search for.
      Returns:
        true if logger exists.

    - #### getName

          public String getName()

      Return the name of this hierarchy.
      Specified by:
        `getName` in interface `LoggerRepositoryEx`
      Returns:
        name of hierarchy

    - #### setName

          public void setName(String repoName)

      Set the name of this repository. Note that once named, a repository cannot be rerenamed.
      Specified by:
        `setName` in interface `LoggerRepositoryEx`
      Parameters:
        `repoName` - name of hierarchy

    - #### getProperties

          public Map getProperties()

      Get the properties specific for this repository.
      Specified by:
        `getProperties` in interface `LoggerRepositoryEx`
      Returns:
        property map.

    - #### getProperty

          public String getProperty(String key)

      Get the property of this repository.
      Specified by:
        `getProperty` in interface `LoggerRepositoryEx`
      Parameters:
        `key` - property key.
      Returns:
        key value or null if not set.

    - #### setProperty

          public void setProperty(String key,
                         String value)

      Set a property by key and value. The property will be shared by all events in this repository.
      Specified by:
        `setProperty` in interface `LoggerRepositoryEx`
      Parameters:
        `key` - property name
        `value` - property value

    - #### setThreshold

          public void setThreshold(String levelStr)

      The string form of `setThreshold(Level)`.
      Specified by:
        `setThreshold` in interface `org.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 level `l` or higher. By default all levels are enabled.
      Specified by:
        `setThreshold` in interface `org.apache.log4j.spi.LoggerRepository`
      Parameters:
        `l` - The minimum level for which logging requests are sent to their appenders.

    - #### getPluginRegistry

          public PluginRegistry getPluginRegistry()

      Return the PluginRegisty for this LoggerRepository.
      Specified by:
        `getPluginRegistry` in interface `LoggerRepositoryEx`
      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 registered `LoggerEventListener`.
      Specified by:
        `fireAddAppenderEvent` in interface `org.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 registered `LoggerEventListener`.
      Specified by:
        `fireRemoveAppenderEvent` in interface `LoggerRepositoryEx`
      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 registered `LoggerEventListener`.
      Specified by:
        `fireLevelChangedEvent` in interface `LoggerRepositoryEx`
      Parameters:
        `logger` - The logger which changed levels.

    - #### fireConfigurationChangedEvent

          public void fireConfigurationChangedEvent()

      Requests that a configuration changed event be sent to any registered `LoggerRepositoryEventListener`.
      Specified by:
        `fireConfigurationChangedEvent` in interface `LoggerRepositoryEx`

    - #### getThreshold

          public org.apache.log4j.Level getThreshold()

      Returns the current threshold.
      Specified by:
        `getThreshold` in interface `org.apache.log4j.spi.LoggerRepository`
      Returns:
        current threshold level
      Since:
        1.2

    - #### getLogger

          public org.apache.log4j.Logger getLogger(String loggerName)

      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 `org.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 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 `org.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

          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 `org.apache.log4j.spi.LoggerRepository`
      Returns:
        enumerator of current loggers

    - #### getErrorList

          public List getErrorList()

      Return the the list of previously encoutered `error items`.
      Specified by:
        `getErrorList` in interface `LoggerRepositoryEx`
      Returns:
        list of errors

    - #### addErrorItem

          public void addErrorItem(ErrorItem errorItem)

      Add an error item to the list of previously encountered errors.
      Specified by:
        `addErrorItem` in interface `LoggerRepositoryEx`
      Parameters:
        `errorItem` - error to add to list of errors.

    - #### getCurrentCategories

          public Enumeration getCurrentCategories()

      Deprecated. Please use `getCurrentLoggers()` instead.
      Get enumerator over current loggers.
      Specified by:
        `getCurrentCategories` in interface `org.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 interface `org.apache.log4j.spi.RendererSupport`
      Returns:
        renderer map

    - #### getRootLogger

          public org.apache.log4j.Logger getRootLogger()

      Get the root of this hierarchy.
      Specified by:
        `getRootLogger` in interface `org.apache.log4j.spi.LoggerRepository`
      Returns:
        root of hierarchy
      Since:
        0.9.0

    - #### isDisabled

          public boolean isDisabled(int level)

      This method will return `true` if this repository is disabled for `level` value passed as parameter and `false` otherwise. See also the `threshold` method.
      Specified by:
        `isDisabled` in interface `org.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 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 `org.apache.log4j.spi.LoggerRepository`
      Since:
        0.8.5

    - #### setRenderer

          public void setRenderer(Class renderedClass,
                         org.apache.log4j.or.ObjectRenderer renderer)

      Used by subclasses to add a renderer to the hierarchy passed as parameter.
      Specified by:
        `setRenderer` in interface `org.apache.log4j.spi.RendererSupport`
      Parameters:
        `renderedClass` - class
        `renderer` - 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 interface `LoggerRepositoryEx`
      Returns:
        true if repository is in original state.

    - #### setPristine

          public void setPristine(boolean state)

      Set the pristine flag.
      Specified by:
        `setPristine` in interface `LoggerRepositoryEx`
      Parameters:
        `state` - state
      See Also:
        `LoggerRepositoryEx.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 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 interface `org.apache.log4j.spi.LoggerRepository`
      Since:
        1.0

    - #### getScheduler

          public Scheduler getScheduler()

      Return this repository's own scheduler. The scheduler is lazily instantiated.
      Specified by:
        `getScheduler` in interface `LoggerRepositoryEx`
      Returns:
        this repository's own scheduler.

    - #### putObject

          public void putObject(String key,
                       Object value)

      Puts object by key.
      Specified by:
        `putObject` in interface `LoggerRepositoryEx`
      Parameters:
        `key` - key, may not be null.
        `value` - object to associate with key.

    - #### getObject

          public Object getObject(String key)

      Get object by key.
      Specified by:
        `getObject` in interface `LoggerRepositoryEx`
      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 interface `LoggerRepositoryEx`
      Parameters:
        `factory` - logger factory.

    - #### getLoggerFactory

          public org.apache.log4j.spi.LoggerFactory getLoggerFactory()

      Get logger factory.
      Specified by:
        `getLoggerFactory` in interface `LoggerRepositoryEx`
      Returns:
        logger factory.

    - #### parseUnrecognizedElement

          public boolean parseUnrecognizedElement(Element element,
                                         Properties props)
                                           throws Exception

      Specified by:
        `parseUnrecognizedElement` in interface `org.apache.log4j.xml.UnrecognizedElementHandler`
      Throws:
        `Exception`

Copyright © 2013 The Apache Software Foundation. Licensed under the Apache License, Version 2.0

Apache Extras for Apache log4j, Apache log4j and Apache are trademarks of the Apache Software Foundation.