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

java.lang.Object
  extended by org.apache.logging.log4j.core.AbstractLifeCycle
      extended by org.apache.logging.log4j.core.filter.AbstractFilterable
          extended by org.apache.logging.log4j.core.config.AbstractConfiguration
All Implemented Interfaces:
Serializable, Configuration, Filterable, LifeCycle
Direct Known Subclasses:
DefaultConfiguration, JsonConfiguration, NullConfiguration, XmlConfiguration

public abstract class AbstractConfiguration
extends AbstractFilterable
implements Configuration

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

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from interface org.apache.logging.log4j.core.LifeCycle
LifeCycle.State
 
Field Summary
protected  boolean isShutdownHookEnabled
           
protected  List<ConfigurationListener> listeners
          Listeners for configuration changes.
protected  ConfigurationMonitor monitor
          The ConfigurationMonitor that checks for configuration changes.
protected  PluginManager pluginManager
           
protected  List<String> pluginPackages
           
protected  Node rootNode
          The root node of the configuration.
 
Fields inherited from class org.apache.logging.log4j.core.AbstractLifeCycle
LOGGER
 
Fields inherited from interface org.apache.logging.log4j.core.config.Configuration
CONTEXT_PROPERTIES
 
Constructor Summary
protected AbstractConfiguration(ConfigurationSource configurationSource)
          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)
          Add a loggerConfig.
 void addLoggerAppender(Logger logger, Appender appender)
          Associates an Appender with a LoggerConfig.
 void addLoggerFilter(Logger logger, Filter filter)
          Associates a Filter with a LoggerConfig.
protected  void createAdvertiser(String advertiserString, ConfigurationSource configSource, byte[] buffer, String contentType)
           
 void createConfiguration(Node node, LogEvent event)
           
protected  void doConfigure()
           
 Advertiser getAdvertiser()
           
 Appender getAppender(String name)
          Returns the Appender with the specified name.
 Map<String,Appender> getAppenders()
          Returns a Map containing all the Appenders and their name.
<T> T
getComponent(String name)
           
 ConfigurationMonitor getConfigurationMonitor()
           
 ConfigurationSource getConfigurationSource()
          Returns the source of this configuration.
 List<CustomLevelConfig> getCustomLevels()
           Returns a list of descriptors of the custom levels defined in the current configuration.
protected  org.apache.logging.log4j.Level getDefaultStatus()
           
 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()
          Returns a Map of all the LoggerConfigs.
 String getName()
          Returns the name of the configuration.
 List<String> getPluginPackages()
          Returns the list of packages to scan for plugins for this Configuration.
 Map<String,String> getProperties()
           
 LoggerConfig getRootLogger()
          Returns the root Logger.
 StrSubstitutor getStrSubstitutor()
           
 boolean isShutdownHookEnabled()
           
 void removeAppender(String name)
          Remove an Appender.
 void removeListener(ConfigurationListener listener)
          Remove a ConfigurationListener.
 void removeLogger(String name)
          Remove a LoggerConfig.
 void setAdvertiser(Advertiser advertiser)
           
 void setConfigurationMonitor(ConfigurationMonitor monitor)
           
 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.
protected static byte[] toByteArray(InputStream is)
          Reads an InputStream using buffered reads into a byte array buffer.
 
Methods inherited from class org.apache.logging.log4j.core.filter.AbstractFilterable
addFilter, getFilter, hasFilter, isFiltered, removeFilter
 
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
 
Methods inherited from interface org.apache.logging.log4j.core.filter.Filterable
addFilter, getFilter, hasFilter, isFiltered, removeFilter
 
Methods inherited from interface org.apache.logging.log4j.core.LifeCycle
getState, isStarted, isStopped
 

Field Detail

rootNode

protected Node rootNode
The root node of the configuration.


listeners

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


monitor

protected ConfigurationMonitor monitor
The ConfigurationMonitor that checks for configuration changes.


isShutdownHookEnabled

protected boolean isShutdownHookEnabled

pluginPackages

protected final List<String> pluginPackages

pluginManager

protected PluginManager pluginManager
Constructor Detail

AbstractConfiguration

protected AbstractConfiguration(ConfigurationSource configurationSource)
Constructor.

Method Detail

getConfigurationSource

public ConfigurationSource getConfigurationSource()
Description copied from interface: Configuration
Returns the source of this configuration.

Specified by:
getConfigurationSource in interface Configuration
Returns:
the source of this configuration

getPluginPackages

public List<String> getPluginPackages()
Description copied from interface: Configuration
Returns the list of packages to scan for plugins for this Configuration.

Specified by:
getPluginPackages in interface Configuration
Returns:
the list of plugin packages.

getProperties

public Map<String,String> getProperties()
Specified by:
getProperties in interface Configuration

start

public void start()
Initialize the configuration.

Specified by:
start in interface LifeCycle
Overrides:
start in class AbstractFilterable

stop

public void stop()
Tear down the configuration.

Specified by:
stop in interface LifeCycle
Overrides:
stop in class AbstractFilterable

isShutdownHookEnabled

public boolean isShutdownHookEnabled()
Specified by:
isShutdownHookEnabled in interface Configuration

setup

protected void setup()

getDefaultStatus

protected org.apache.logging.log4j.Level getDefaultStatus()

createAdvertiser

protected void createAdvertiser(String advertiserString,
                                ConfigurationSource configSource,
                                byte[] buffer,
                                String contentType)

getComponent

public <T> T 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()

setName

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

Parameters:
name - The name.

getName

public String getName()
Returns 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)
Returns the Appender with the specified name.

Specified by:
getAppender in interface Configuration
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()
Returns a Map containing all the Appenders and their name.

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

addAppender

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

Specified by:
addAppender in interface Configuration
Parameters:
appender - The Appender to add.

getStrSubstitutor

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

setConfigurationMonitor

public void setConfigurationMonitor(ConfigurationMonitor monitor)
Specified by:
setConfigurationMonitor in interface Configuration

getConfigurationMonitor

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

setAdvertiser

public void setAdvertiser(Advertiser advertiser)
Specified by:
setAdvertiser in interface Configuration

getAdvertiser

public Advertiser getAdvertiser()
Specified by:
getAdvertiser 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 LoggerConfigs 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.

getCustomLevels

public List<CustomLevelConfig> getCustomLevels()
Description copied from interface: Configuration

Returns a list of descriptors of the custom levels defined in the current configuration. The returned list does not include custom levels that are defined in code with direct calls to Level.forName(String, int).

Note that the list does not include levels of previous configurations. For example, suppose a configuration contains custom levels A, B and C. The configuration is then modified to contain custom levels B, C and D. For the new configuration, this method will return only {B, C, D}, that is, only the custom levels defined in this configuration. The previously defined level A still exists (and can be obtained with Level.getLevel(String)), it is just not in the current configuration. Level.values() will return {A, B, C, D and the built-in levels}.

Specified by:
getCustomLevels in interface Configuration
Returns:
the custom levels defined in the current configuration

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()
Returns 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)
Add a loggerConfig. The LoggerConfig must already be configured with Appenders, Filters, etc. After addLogger is called LoggerContext.updateLoggers must be called.

Specified by:
addLogger in interface Configuration
Parameters:
name - The name of the Logger.
loggerConfig - The LoggerConfig.

removeLogger

public void removeLogger(String name)
Remove a LoggerConfig.

Specified by:
removeLogger in interface Configuration
Parameters:
name - The name of the Logger.

createConfiguration

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

toByteArray

protected static byte[] toByteArray(InputStream is)
                             throws IOException
Reads an InputStream using buffered reads into a byte array buffer. The given InputStream will remain open after invocation of this method.

Parameters:
is - the InputStream to read into a byte array buffer.
Returns:
a byte array of the InputStream contents.
Throws:
IOException - if the read method of the provided InputStream throws this exception.


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.