Class AbstractConfiguration
- java.lang.Object
-
- org.apache.logging.log4j.core.AbstractLifeCycle
-
- org.apache.logging.log4j.core.filter.AbstractFilterable
-
- org.apache.logging.log4j.core.config.AbstractConfiguration
-
- All Implemented Interfaces:
Configuration
,Filterable
,LifeCycle
,LifeCycle2
- Direct Known Subclasses:
BuiltConfiguration
,CompositeConfiguration
,DefaultConfiguration
,JsonConfiguration
,Log4j1Configuration
,NullConfiguration
,XmlConfiguration
public abstract class AbstractConfiguration extends AbstractFilterable implements Configuration
The base Configuration. Many configuration implementations will extend this class.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.apache.logging.log4j.core.filter.AbstractFilterable
AbstractFilterable.Builder<B extends AbstractFilterable.Builder<B>>
-
Nested classes/interfaces inherited from interface org.apache.logging.log4j.core.LifeCycle
LifeCycle.State
-
-
Field Summary
Fields Modifier and Type Field Description protected boolean
isShutdownHookEnabled
Shutdown hook is enabled by default.protected List<ConfigurationListener>
listeners
Listeners for configuration changes.protected PluginManager
pluginManager
The plugin manager.protected List<String>
pluginPackages
Packages found in configuration "packages" attribute.protected Node
rootNode
The root node of the configuration.protected ScriptManager
scriptManager
The Script manager.protected long
shutdownTimeoutMillis
Shutdown timeout in milliseconds.-
Fields inherited from class org.apache.logging.log4j.core.AbstractLifeCycle
DEFAULT_STOP_TIMEOUT, DEFAULT_STOP_TIMEUNIT, LOGGER
-
Fields inherited from interface org.apache.logging.log4j.core.config.Configuration
CONTEXT_PROPERTIES
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
AbstractConfiguration(LoggerContext loggerContext, ConfigurationSource configurationSource)
Constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addAppender(Appender appender)
Adds an Appender to the configuration.void
addComponent(String componentName, Object obj)
void
addListener(ConfigurationListener listener)
Add a listener for changes on the configuration.void
addLogger(String loggerName, 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()
<T extends Appender>
TgetAppender(String appenderName)
Returns the Appender with the specified name.Map<String,Appender>
getAppenders()
Returns a Map containing all the Appenders and their name.AsyncLoggerConfigDelegate
getAsyncLoggerConfigDelegate()
Returns theAsyncLoggerConfigDelegate
shared by allAsyncLoggerConfig
instances defined in this Configuration.<T> T
getComponent(String componentName)
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 Level
getDefaultStatus()
LoggerConfig
getLogger(String loggerName)
Returns the LoggerConfig with the specified name.LoggerConfig
getLoggerConfig(String loggerName)
Locates the appropriate LoggerConfig for a Logger name.LoggerContext
getLoggerContext()
Gets the logger context.Map<String,LoggerConfig>
getLoggers()
Returns a Map of all the LoggerConfigs.String
getName()
Returns the name of the configuration.NanoClock
getNanoClock()
Returns theNanoClock
instance for this configuration.PluginManager
getPluginManager()
List<String>
getPluginPackages()
Returns the list of packages to scan for plugins for this Configuration.Map<String,String>
getProperties()
ReliabilityStrategy
getReliabilityStrategy(LoggerConfig loggerConfig)
LoggerConfig
getRootLogger()
Returns the root Logger.Node
getRootNode()
ConfigurationScheduler
getScheduler()
ScriptManager
getScriptManager()
long
getShutdownTimeoutMillis()
StrSubstitutor
getStrSubstitutor()
WatchManager
getWatchManager()
Return the WatchManager.void
initialize()
Initialize the configuration.protected void
initializeWatchers(Reconfigurable reconfigurable, ConfigurationSource configSource, int monitorIntervalSeconds)
boolean
isShutdownHookEnabled()
protected void
preConfigure(Node node)
void
removeAppender(String appenderName)
Remove an Appender.void
removeListener(ConfigurationListener listener)
Remove a ConfigurationListener.void
removeLogger(String loggerName)
Remove a LoggerConfig.void
setAdvertiser(Advertiser advertiser)
void
setLoggerAdditive(Logger logger, boolean additive)
Marks a LoggerConfig as additive.void
setName(String name)
Set the name of the configuration.void
setNanoClock(NanoClock nanoClock)
Sets theNanoClock
instance for this configuration.void
setPluginManager(PluginManager pluginManager)
void
setScriptManager(ScriptManager scriptManager)
protected void
setToDefault()
void
setup()
void
start()
Start the configuration.boolean
stop(long timeout, TimeUnit timeUnit)
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, getPropertyArray, hasFilter, isFiltered, removeFilter, stop
-
Methods inherited from class org.apache.logging.log4j.core.AbstractLifeCycle
equalsImpl, getState, getStatusLogger, hashCodeImpl, isInitialized, isStarted, isStarting, isStopped, isStopping, setStarted, setStarting, setState, setStopped, setStopping, stop, stop
-
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
-
-
-
-
Field Detail
-
rootNode
protected Node rootNode
The root node of the configuration.
-
listeners
protected final List<ConfigurationListener> listeners
Listeners for configuration changes.
-
pluginPackages
protected final List<String> pluginPackages
Packages found in configuration "packages" attribute.
-
pluginManager
protected PluginManager pluginManager
The plugin manager.
-
isShutdownHookEnabled
protected boolean isShutdownHookEnabled
Shutdown hook is enabled by default.
-
shutdownTimeoutMillis
protected long shutdownTimeoutMillis
Shutdown timeout in milliseconds.
-
scriptManager
protected ScriptManager scriptManager
The Script manager.
-
-
Constructor Detail
-
AbstractConfiguration
protected AbstractConfiguration(LoggerContext loggerContext, ConfigurationSource configurationSource)
Constructor.
-
-
Method Detail
-
getConfigurationSource
public ConfigurationSource getConfigurationSource()
Description copied from interface:Configuration
Returns the source of this configuration.- Specified by:
getConfigurationSource
in interfaceConfiguration
- Returns:
- the source of this configuration, never
null
, but may beConfigurationSource.NULL_SOURCE
orConfigurationSource.COMPOSITE_SOURCE
-
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 interfaceConfiguration
- Returns:
- the list of plugin packages.
-
getProperties
public Map<String,String> getProperties()
- Specified by:
getProperties
in interfaceConfiguration
-
getScriptManager
public ScriptManager getScriptManager()
- Specified by:
getScriptManager
in interfaceConfiguration
-
setScriptManager
public void setScriptManager(ScriptManager scriptManager)
-
getPluginManager
public PluginManager getPluginManager()
-
setPluginManager
public void setPluginManager(PluginManager pluginManager)
-
getWatchManager
public WatchManager getWatchManager()
Description copied from interface:Configuration
Return the WatchManager.- Specified by:
getWatchManager
in interfaceConfiguration
- Returns:
- the WatchManager.
-
getScheduler
public ConfigurationScheduler getScheduler()
- Specified by:
getScheduler
in interfaceConfiguration
-
getRootNode
public Node getRootNode()
-
getAsyncLoggerConfigDelegate
public AsyncLoggerConfigDelegate getAsyncLoggerConfigDelegate()
Description copied from interface:Configuration
Returns theAsyncLoggerConfigDelegate
shared by allAsyncLoggerConfig
instances defined in this Configuration.- Specified by:
getAsyncLoggerConfigDelegate
in interfaceConfiguration
- Returns:
- the
AsyncLoggerConfigDelegate
-
initialize
public void initialize()
Initialize the configuration.- Specified by:
initialize
in interfaceLifeCycle
- Overrides:
initialize
in classAbstractLifeCycle
-
initializeWatchers
protected void initializeWatchers(Reconfigurable reconfigurable, ConfigurationSource configSource, int monitorIntervalSeconds)
-
start
public void start()
Start the configuration.- Specified by:
start
in interfaceLifeCycle
- Overrides:
start
in classAbstractFilterable
-
stop
public boolean stop(long timeout, TimeUnit timeUnit)
Tear down the configuration.- Specified by:
stop
in interfaceLifeCycle2
- Overrides:
stop
in classAbstractFilterable
- Parameters:
timeout
- the maximum time to waittimeUnit
- the time unit of the timeout argument- Returns:
- true if the receiver was stopped cleanly and normally, false otherwise.
-
isShutdownHookEnabled
public boolean isShutdownHookEnabled()
- Specified by:
isShutdownHookEnabled
in interfaceConfiguration
-
getShutdownTimeoutMillis
public long getShutdownTimeoutMillis()
- Specified by:
getShutdownTimeoutMillis
in interfaceConfiguration
-
setup
public void setup()
-
getDefaultStatus
protected Level getDefaultStatus()
-
createAdvertiser
protected void createAdvertiser(String advertiserString, ConfigurationSource configSource, byte[] buffer, String contentType)
-
getComponent
public <T> T getComponent(String componentName)
- Specified by:
getComponent
in interfaceConfiguration
-
addComponent
public void addComponent(String componentName, Object obj)
- Specified by:
addComponent
in interfaceConfiguration
-
preConfigure
protected void preConfigure(Node node)
-
doConfigure
protected void doConfigure()
-
setToDefault
protected void setToDefault()
-
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 interfaceConfiguration
- Returns:
- the name of the configuration.
-
addListener
public void addListener(ConfigurationListener listener)
Add a listener for changes on the configuration.- Specified by:
addListener
in interfaceConfiguration
- Parameters:
listener
- The ConfigurationListener to add.
-
removeListener
public void removeListener(ConfigurationListener listener)
Remove a ConfigurationListener.- Specified by:
removeListener
in interfaceConfiguration
- Parameters:
listener
- The ConfigurationListener to remove.
-
getAppender
public <T extends Appender> T getAppender(String appenderName)
Returns the Appender with the specified name.- Specified by:
getAppender
in interfaceConfiguration
- Type Parameters:
T
- The expected Appender type.- Parameters:
appenderName
- 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 interfaceConfiguration
- 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 interfaceConfiguration
- Parameters:
appender
- The Appender to add.
-
getStrSubstitutor
public StrSubstitutor getStrSubstitutor()
- Specified by:
getStrSubstitutor
in interfaceConfiguration
-
setAdvertiser
public void setAdvertiser(Advertiser advertiser)
- Specified by:
setAdvertiser
in interfaceConfiguration
-
getAdvertiser
public Advertiser getAdvertiser()
- Specified by:
getAdvertiser
in interfaceConfiguration
-
getReliabilityStrategy
public ReliabilityStrategy getReliabilityStrategy(LoggerConfig loggerConfig)
- Specified by:
getReliabilityStrategy
in interfaceConfiguration
-
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 interfaceConfiguration
- 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 interfaceConfiguration
- Parameters:
logger
- The Logger the Footer 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 interfaceConfiguration
- 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 appenderName)
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:
appenderName
- 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 interfaceConfiguration
- Returns:
- the custom levels defined in the current configuration
-
getLoggerConfig
public LoggerConfig getLoggerConfig(String loggerName)
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 interfaceConfiguration
- Parameters:
loggerName
- The Logger name.- Returns:
- The located LoggerConfig.
-
getLoggerContext
public LoggerContext getLoggerContext()
Description copied from interface:Configuration
Gets the logger context.- Specified by:
getLoggerContext
in interfaceConfiguration
- Returns:
- the logger context.
-
getRootLogger
public LoggerConfig getRootLogger()
Returns the root Logger.- Specified by:
getRootLogger
in interfaceConfiguration
- Returns:
- the root Logger.
-
getLoggers
public Map<String,LoggerConfig> getLoggers()
Returns a Map of all the LoggerConfigs.- Specified by:
getLoggers
in interfaceConfiguration
- Returns:
- a Map with each entry containing the name of the Logger and the LoggerConfig.
-
getLogger
public LoggerConfig getLogger(String loggerName)
Returns the LoggerConfig with the specified name.- Parameters:
loggerName
- The Logger name.- Returns:
- The LoggerConfig or null if no match was found.
-
addLogger
public void addLogger(String loggerName, 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 interfaceConfiguration
- Parameters:
loggerName
- The name of the Logger.loggerConfig
- The LoggerConfig.
-
removeLogger
public void removeLogger(String loggerName)
Remove a LoggerConfig.- Specified by:
removeLogger
in interfaceConfiguration
- Parameters:
loggerName
- The name of the Logger.
-
createConfiguration
public void createConfiguration(Node node, LogEvent event)
- Specified by:
createConfiguration
in interfaceConfiguration
-
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 theread
method of the provided InputStream throws this exception.
-
getNanoClock
public NanoClock getNanoClock()
Description copied from interface:Configuration
Returns theNanoClock
instance for this configuration.- Specified by:
getNanoClock
in interfaceConfiguration
- Returns:
- the nano clock
-
setNanoClock
public void setNanoClock(NanoClock nanoClock)
Description copied from interface:Configuration
Sets theNanoClock
instance for this configuration.- Specified by:
setNanoClock
in interfaceConfiguration
- Parameters:
nanoClock
- the new nano clock for this configuration. Must be non-null.
-
-