org.apache.logging.log4j.core.config
Class BaseConfiguration

java.lang.Object
  extended by org.apache.logging.log4j.core.filter.Filterable
      extended by org.apache.logging.log4j.core.config.BaseConfiguration
All Implemented Interfaces:
Configuration, Filtering
Direct Known Subclasses:
DefaultConfiguration, JSONConfiguration, NullConfiguration, XMLConfiguration

public class BaseConfiguration
extends Filterable
implements Configuration

The Base Configuration. Many configuration implementations will extend this class.


Field Summary
protected  List<ConfigurationListener> listeners
          Listeners for configuration changes.
protected static Logger LOGGER
          Allow subclasses access to the status logger without creating another instance.
protected  ConfigurationMonitor monitor
          The ConfigurationMonitor that checks for configuration changes.
protected  PluginManager pluginManager
          The Plugin Manager.
protected  Node rootNode
          The root node of the configuration.
 
Constructor Summary
protected BaseConfiguration()
          Constructor.
 
Method Summary
 void addAppender(Appender appender)
          Adds an Appender to the configuration.
 void addComponent(String name, Object obj)
           
 void addListener(ConfigurationListener listener)
          Add a listener for changes on the configuration.
 void addLogger(String name, LoggerConfig loggerConfig)
          Adding a logger cannot be done atomically so is not allowed in an active configuration.
 void addLoggerAppender(Logger logger, Appender appender)
          Associates an Appender with a LoggerConfig.
 void addLoggerFilter(Logger logger, Filter filter)
          Associates a Filter with a LoggerConfig.
 void createConfiguration(Node node, LogEvent event)
           
protected  void doConfigure()
           
 Appender getAppender(String name)
          Return the Appender with the specified name.
 Map<String,Appender> getAppenders()
          Return a Map containing all the Appenders and their name.
 Object getComponent(String name)
           
 ConfigurationMonitor getConfigurationMonitor()
           
 LoggerConfig getLogger(String name)
          Returns the LoggerConfig with the specified name.
 LoggerConfig getLoggerConfig(String name)
          Locates the appropriate LoggerConfig for a Logger name.
 Map<String,LoggerConfig> getLoggers()
          Return a Map of all the LoggerConfigs.
 String getName()
          Return the name of the configuration.
protected  PluginManager getPluginManager()
           
 LoggerConfig getRootLogger()
          Returns the root Logger.
 StrSubstitutor getSubst()
           
 void removeAppender(String name)
          Remove an Appender.
 void removeListener(ConfigurationListener listener)
          Remove a ConfigurationListener.
 void removeLogger(String name)
          Removing a logger cannot be done atomically so is not allowed in an active configuration.
 void setLoggerAdditive(Logger logger, boolean additive)
          Marks a LoggerConfig as additive.
 void setName(String name)
          Set the name of the configuration.
protected  void setup()
           
 void start()
          Initialize the configuration.
 void stop()
          Tear down the configuration.
 
Methods inherited from class org.apache.logging.log4j.core.filter.Filterable
addFilter, getFilter, hasFilter, isFiltered, removeFilter, startFilter, stopFilter
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.apache.logging.log4j.core.filter.Filtering
addFilter, getFilter, hasFilter, isFiltered, removeFilter
 

Field Detail

LOGGER

protected static final Logger LOGGER
Allow subclasses access to the status logger without creating another instance.


rootNode

protected Node rootNode
The root node of the configuration.


pluginManager

protected PluginManager pluginManager
The Plugin Manager.


listeners

protected final List<ConfigurationListener> listeners
Listeners for configuration changes.


monitor

protected ConfigurationMonitor monitor
The ConfigurationMonitor that checks for configuration changes.

Constructor Detail

BaseConfiguration

protected BaseConfiguration()
Constructor.

Method Detail

start

public void start()
Initialize the configuration.

Specified by:
start in interface Configuration

stop

public void stop()
Tear down the configuration.

Specified by:
stop in interface Configuration

setup

protected void setup()

getComponent

public Object getComponent(String name)
Specified by:
getComponent in interface Configuration

addComponent

public void addComponent(String name,
                         Object obj)
Specified by:
addComponent in interface Configuration

doConfigure

protected void doConfigure()

getPluginManager

protected PluginManager getPluginManager()

setName

public void setName(String name)
Set the name of the configuration.

Parameters:
name - The name.

getName

public String getName()
Return the name of the configuration.

Specified by:
getName in interface Configuration
Returns:
the name of the configuration.

addListener

public void addListener(ConfigurationListener listener)
Add a listener for changes on the configuration.

Specified by:
addListener in interface Configuration
Parameters:
listener - The ConfigurationListener to add.

removeListener

public void removeListener(ConfigurationListener listener)
Remove a ConfigurationListener.

Specified by:
removeListener in interface Configuration
Parameters:
listener - The ConfigurationListener to remove.

getAppender

public Appender getAppender(String name)
Return the Appender with the specified name.

Parameters:
name - The name of the Appender.
Returns:
the Appender with the specified name or null if the Appender cannot be located.

getAppenders

public Map<String,Appender> getAppenders()
Return a Map containing all the Appenders and their name.

Specified by:
getAppenders in interface Configuration
Returns:
A Map containing each Appender's naem and the Appender object.

addAppender

public void addAppender(Appender appender)
Adds an Appender to the configuration.

Parameters:
appender - The Appender to add.

getSubst

public StrSubstitutor getSubst()
Specified by:
getSubst in interface Configuration

getConfigurationMonitor

public ConfigurationMonitor getConfigurationMonitor()
Specified by:
getConfigurationMonitor in interface Configuration

addLoggerAppender

public void addLoggerAppender(Logger logger,
                              Appender appender)
Associates an Appender with a LoggerConfig. This method is synchronized in case a Logger with the same name is being updated at the same time. Note: This method is not used when configuring via configuration. It is primarily used by unit tests.

Specified by:
addLoggerAppender in interface Configuration
Parameters:
logger - The Logger the Appender will be associated with.
appender - The Appender.

addLoggerFilter

public void addLoggerFilter(Logger logger,
                            Filter filter)
Associates a Filter with a LoggerConfig. This method is synchronized in case a Logger with the same name is being updated at the same time. Note: This method is not used when configuring via configuration. It is primarily used by unit tests.

Specified by:
addLoggerFilter in interface Configuration
Parameters:
logger - The Logger the Fo;ter will be associated with.
filter - The Filter.

setLoggerAdditive

public void setLoggerAdditive(Logger logger,
                              boolean additive)
Marks a LoggerConfig as additive. This method is synchronized in case a Logger with the same name is being updated at the same time. Note: This method is not used when configuring via configuration. It is primarily used by unit tests.

Specified by:
setLoggerAdditive in interface Configuration
Parameters:
logger - The Logger the Appender will be associated with.
additive - True if the LoggerConfig should be additive, false otherwise.

removeAppender

public void removeAppender(String name)
Remove an Appender. First removes any associations between LoggerContigs and the Appender, removes the Appender from this appender list and then stops the appender. This method is synchronized in case an Appender with the same name is being added during the removal.

Parameters:
name - the name of the appender to remove.

getLoggerConfig

public LoggerConfig getLoggerConfig(String name)
Locates the appropriate LoggerConfig for a Logger name. This will remove tokens from the package name as necessary or return the root LoggerConfig if no other matches were found.

Specified by:
getLoggerConfig in interface Configuration
Parameters:
name - The Logger name.
Returns:
The located LoggerConfig.

getRootLogger

public LoggerConfig getRootLogger()
Returns the root Logger.

Returns:
the root Logger.

getLoggers

public Map<String,LoggerConfig> getLoggers()
Return a Map of all the LoggerConfigs.

Specified by:
getLoggers in interface Configuration
Returns:
a Map with each entry containing the name of the Logger and the LoggerConfig.

getLogger

public LoggerConfig getLogger(String name)
Returns the LoggerConfig with the specified name.

Parameters:
name - The Logger name.
Returns:
The LoggerConfig or null if no match was found.

addLogger

public void addLogger(String name,
                      LoggerConfig loggerConfig)
Adding a logger cannot be done atomically so is not allowed in an active configuration. Adding or removing a Logger requires creating a new configuration and then switching.

Parameters:
name - The name of the Logger.
loggerConfig - The LoggerConfig.

removeLogger

public void removeLogger(String name)
Removing a logger cannot be done atomically so is not allowed in an active configuration. Adding or removing a Logger requires creating a new configuration and then switching.

Parameters:
name - The name of the Logger.

createConfiguration

public void createConfiguration(Node node,
                                LogEvent event)
Specified by:
createConfiguration in interface Configuration


Copyright © 1999-2012 Apache Software Foundation. All Rights Reserved.