Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.apache.logging.log4j.core
Class LoggerContext

    java.lang.Object
      org.apache.logging.log4j.core.AbstractLifeCycle
          org.apache.logging.log4j.core.LoggerContext

All Implemented Interfaces:
  Serializable, ConfigurationListener, LifeCycle, org.apache.logging.log4j.spi.LoggerContext

Direct Known Subclasses:
  AsyncLoggerContext

    public class LoggerContext

extends AbstractLifeCycle
implements org.apache.logging.log4j.spi.LoggerContext, ConfigurationListener

The LoggerContext is the anchor for the logging system. It maintains a list of all the loggers requested by applications and a reference to the Configuration. The Configuration will contain the configured loggers, appenders, filters, etc and will be atomically updated whenever a reconfigure occurs.

See Also:
  Serialized Form

Nested Class Summary

Nested classes/interfaces inherited from interface org.apache.logging.log4j.core.LifeCycle
`LifeCycle.State`

Field Summary
`static String` | `PROPERTY_CONFIG`

Fields inherited from class org.apache.logging.log4j.core.AbstractLifeCycle
`LOGGER`

Constructor Summary
`LoggerContext(String name)` Constructor taking only a name.
`LoggerContext(String name, Object externalContext)` Constructor taking a name and a reference to an external context.
`LoggerContext(String name, Object externalContext, String configLocn)` Constructor taking a name external context and a configuration location String.
`LoggerContext(String name, Object externalContext, URI configLocn)` Constructor taking a name, external context and a configuration URI.

Method Summary
`void` | `addFilter(Filter filter)` Adds a Filter to the Configuration.
`void` | `addPropertyChangeListener(PropertyChangeListener listener)`
`URI` | `getConfigLocation()` Returns the initial configuration location or `null`.
`Configuration` | `getConfiguration()` Returns the current Configuration.
`Object` | `getExternalContext()` Returns the external context.
`Logger` | `getLogger(String name)` Obtains a Logger from the Context.
`Logger` | `getLogger(String name, org.apache.logging.log4j.message.MessageFactory messageFactory)` Obtains a Logger from the Context.
`Collection<Logger>` | `getLoggers()` Gets a collection of the current loggers.
`String` | `getName()` Gets the name.
`boolean` | `hasLogger(String name)` Determines if the specified Logger exists.
`protected Logger` | `newInstance(LoggerContext ctx, String name, org.apache.logging.log4j.message.MessageFactory messageFactory)`
`void` | `onChange(Reconfigurable reconfigurable)` Causes a reconfiguration to take place when the underlying configuration file changes.
`void` | `reconfigure()` Reconfigure the context.
`void` | `removeFilter(Filter filter)` Removes a Filter from the current Configuration.
`void` | `removePropertyChangeListener(PropertyChangeListener listener)`
`void` | `setConfigLocation(URI configLocation)` Sets the configLocation to the specified value and reconfigures this context.
`void` | `setExternalContext(Object context)` Sets the external context.
`void` | `start()`
`void` | `start(Configuration config)` Starts with a specific configuration.
`void` | `stop()`
`void` | `updateLoggers()` Causes all Loggers to be updated against the current Configuration.
`void` | `updateLoggers(Configuration config)` Causes all Logger to be updated against the specified Configuration.

Methods inherited from class org.apache.logging.log4j.core.AbstractLifeCycle
`equalsImpl, getState, hashCodeImpl, isInitialized, isStarted, isStarting, isStopped, isStopping, setStarted, setStarting, setState, setStopped, setStopping`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### PROPERTY_CONFIG

    public static final String PROPERTY_CONFIG

See Also:
  Constant Field Values

Constructor Detail

### LoggerContext

    public LoggerContext(String name)

  Constructor taking only a name.

  Parameters:
    `name` - The context name.

### LoggerContext

    public LoggerContext(String name,
                         Object externalContext)

  Constructor taking a name and a reference to an external context.

  Parameters:
    `name` - The context name.
    `externalContext` - The external context.

### LoggerContext

    public LoggerContext(String name,
                         Object externalContext,
                         URI configLocn)

  Constructor taking a name, external context and a configuration URI.

  Parameters:
    `name` - The context name.
    `externalContext` - The external context.
    `configLocn` - The location of the configuration as a URI.

### LoggerContext

    public LoggerContext(String name,
                         Object externalContext,
                         String configLocn)

  Constructor taking a name external context and a configuration location String. The location must be resolvable to a File.

  Parameters:
    `name` - The configuration location.
    `externalContext` - The external context.
    `configLocn` - The configuration location.

Method Detail

### start

    public void start()

  Specified by:
    `start` in interface `LifeCycle`
  Overrides:
    `start` in class `AbstractLifeCycle`

### start

    public void start(Configuration config)

  Starts with a specific configuration.

  Parameters:
    `config` - The new Configuration.

### stop

    public void stop()

  Specified by:
    `stop` in interface `LifeCycle`
  Overrides:
    `stop` in class `AbstractLifeCycle`

### getName

    public String getName()

  Gets the name.

  Returns:
    the name.

### setExternalContext

    public void setExternalContext(Object context)

  Sets the external context.

  Parameters:
    `context` - The external context.

### getExternalContext

    public Object getExternalContext()

  Returns the external context.

  Specified by:
    `getExternalContext` in interface `org.apache.logging.log4j.spi.LoggerContext`
  Returns:
    The external context.

### getLogger

    public Logger getLogger(String name)

  Obtains a Logger from the Context.

  Specified by:
    `getLogger` in interface `org.apache.logging.log4j.spi.LoggerContext`
  Parameters:
    `name` - The name of the Logger to return.
  Returns:
    The Logger.

### getLoggers

    public Collection<Logger> getLoggers()

  Gets a collection of the current loggers.

  Whether this collection is a copy of the underlying collection or not is undefined. Therefore, modify this collection at your own risk.

  Returns:
    a collection of the current loggers.

### getLogger

    public Logger getLogger(String name,
                            org.apache.logging.log4j.message.MessageFactory messageFactory)

  Obtains a Logger from the Context.

  Specified by:
    `getLogger` in interface `org.apache.logging.log4j.spi.LoggerContext`
  Parameters:
    `name` - The name of the Logger to return.
    `messageFactory` - The message factory is used only when creating a logger, subsequent use does not change the logger but will log a warning if mismatched.
  Returns:
    The Logger.

### hasLogger

    public boolean hasLogger(String name)

  Determines if the specified Logger exists.

  Specified by:
    `hasLogger` in interface `org.apache.logging.log4j.spi.LoggerContext`
  Parameters:
    `name` - The Logger name to search for.
  Returns:
    True if the Logger exists, false otherwise.

### getConfiguration

    public Configuration getConfiguration()

  Returns the current Configuration. The Configuration will be replaced when a reconfigure occurs.

  Returns:
    The Configuration.

### addFilter

    public void addFilter(Filter filter)

  Adds a Filter to the Configuration. Filters that are added through the API will be lost when a reconfigure occurs.

  Parameters:
    `filter` - The Filter to add.

### removeFilter

    public void removeFilter(Filter filter)

  Removes a Filter from the current Configuration.

  Parameters:
    `filter` - The Filter to remove.

### addPropertyChangeListener

    public void addPropertyChangeListener(PropertyChangeListener listener)

### removePropertyChangeListener

    public void removePropertyChangeListener(PropertyChangeListener listener)

### getConfigLocation

    public URI getConfigLocation()

  Returns the initial configuration location or `null`. The returned value may not be the location of the current configuration. Use `getConfiguration()`.`getConfigurationSource()`.`getLocation()` to get the actual source of the current configuration.

  Returns:
    the initial configuration location or `null`

### setConfigLocation

    public void setConfigLocation(URI configLocation)

  Sets the configLocation to the specified value and reconfigures this context.

  Parameters:
    `configLocation` - the location of the new configuration

### reconfigure

    public void reconfigure()

  Reconfigure the context. Log4j does not remove Loggers during a reconfiguration. Log4j will create new LoggerConfig objects and Log4j will point the Loggers at the new LoggerConfigs. Log4j will free the old LoggerConfig, along with old Appenders and Filters.

### updateLoggers

    public void updateLoggers()

  Causes all Loggers to be updated against the current Configuration.

### updateLoggers

    public void updateLoggers(Configuration config)

  Causes all Logger to be updated against the specified Configuration.

  Parameters:
    `config` - The Configuration.

### onChange

    public void onChange(Reconfigurable reconfigurable)

  Causes a reconfiguration to take place when the underlying configuration file changes.

  Specified by:
    `onChange` in interface `ConfigurationListener`
  Parameters:
    `reconfigurable` - The Configuration that can be reconfigured.

### newInstance

    protected Logger newInstance(LoggerContext ctx,
                                 String name,
                                 org.apache.logging.log4j.message.MessageFactory messageFactory)

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 1999-2015 Apache Software Foundation. All Rights Reserved.
Apache Logging, Apache Log4j, Log4j, Apache, the Apache feather logo, the Apache Logging project logo, and the Apache Log4j logo are trademarks of The Apache Software Foundation.