Class AbstractConfiguration
- All Implemented Interfaces:
Configuration,Filterable,LifeCycle,LifeCycle2
- Direct Known Subclasses:
BuiltConfiguration,CompositeConfiguration,DefaultConfiguration,JsonConfiguration,NullConfiguration,XmlConfiguration
-
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
FieldsModifier and TypeFieldDescriptionprotected booleanShutdown hook is enabled by default.protected final List<ConfigurationListener>Listeners for configuration changes.protected PluginManagerThe plugin manager.Packages found in configuration "packages" attribute.protected NodeThe root node of the configuration.protected ScriptManagerThe Script manager.protected longShutdown timeout in milliseconds.Fields inherited from class org.apache.logging.log4j.core.AbstractLifeCycle
DEFAULT_STOP_TIMEOUT, DEFAULT_STOP_TIMEUNIT, LOGGERFields inherited from interface org.apache.logging.log4j.core.config.Configuration
CONTEXT_PROPERTIES -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedAbstractConfiguration(LoggerContext loggerContext, ConfigurationSource configurationSource) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddAppender(Appender appender) Adds an Appender to the configuration.voidaddComponent(String componentName, Object obj) voidaddListener(ConfigurationListener listener) Add a listener for changes on the configuration.voidaddLogger(String loggerName, LoggerConfig loggerConfig) Add a loggerConfig.voidaddLoggerAppender(Logger logger, Appender appender) Associates an Appender with a LoggerConfig.voidaddLoggerFilter(Logger logger, Filter filter) Associates a Filter with a LoggerConfig.protected voidcreateAdvertiser(String advertiserString, ConfigurationSource configSource, byte[] buffer, String contentType) voidcreateConfiguration(Node node, LogEvent event) createPluginObject(PluginType<?> type, Node node) This method is used by Arbiters to create specific children.protected void<T extends Appender>
TgetAppender(String appenderName) Returns the Appender with the specified name.Returns a Map containing all the Appenders and their name.Returns theAsyncLoggerConfigDelegateshared by allAsyncLoggerConfiginstances defined in this Configuration.Returns theAsyncWaitStrategyFactorydefined in this Configuration; this factory is used to create the LMAX disruptorWaitStrategyused by the disruptor ringbuffer for Async Loggers.<T> TgetComponent(String componentName) Returns the source of this configuration.Returns a list of descriptors of the custom levels defined in the current configuration.static Levelprotected LevelReturns the LoggerConfig with the specified name.getLoggerConfig(String loggerName) Locates the appropriate LoggerConfig for a Logger name.Gets the logger context.Returns a Map of all the LoggerConfigs.getName()Returns the name of the configuration.Returns theNanoClockinstance for this configuration.Returns the list of packages to scan for plugins for this Configuration.getReliabilityStrategy(LoggerConfig loggerConfig) Returns the root Logger.longReturn the WatchManager.voidInitialize the configuration.protected voidinitializeWatchers(Reconfigurable reconfigurable, ConfigurationSource configSource, int monitorIntervalSeconds) booleanprotected voidpreConfigure(Node node) protected voidprocessConditionals(Node node) Process conditions by evaluating them and including the children of conditions that are true and discarding those that are not.processSelect(Node selectNode, PluginType<?> type) Handle Select nodes.voidremoveAppender(String appenderName) Remove an Appender.voidremoveListener(ConfigurationListener listener) Remove a ConfigurationListener.voidremoveLogger(String loggerName) Remove a LoggerConfig.voidsetAdvertiser(Advertiser advertiser) voidsetLoggerAdditive(Logger logger, boolean additive) Marks a LoggerConfig as additive.voidSet the name of the configuration.voidsetNanoClock(NanoClock nanoClock) Sets theNanoClockinstance for this configuration.voidsetPluginManager(PluginManager pluginManager) voidsetScriptManager(ScriptManager scriptManager) protected voidvoidsetup()voidstart()Start the configuration.booleanTear down the configuration.protected static byte[]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, stopMethods inherited from class org.apache.logging.log4j.core.AbstractLifeCycle
equalsImpl, getState, getStatusLogger, hashCodeImpl, isInitialized, isStarted, isStarting, isStopped, isStopping, setStarted, setStarting, setState, setStopped, setStopping, stop, stopMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.apache.logging.log4j.core.filter.Filterable
addFilter, getFilter, hasFilter, isFiltered, removeFilter
-
Field Details
-
rootNode
The root node of the configuration. -
listeners
Listeners for configuration changes. -
pluginPackages
Packages found in configuration "packages" attribute. -
pluginManager
The plugin manager. -
isShutdownHookEnabled
protected boolean isShutdownHookEnabledShutdown hook is enabled by default. -
shutdownTimeoutMillis
protected long shutdownTimeoutMillisShutdown timeout in milliseconds. -
scriptManager
The Script manager.
-
-
Constructor Details
-
AbstractConfiguration
protected AbstractConfiguration(LoggerContext loggerContext, ConfigurationSource configurationSource) Constructor.
-
-
Method Details
-
getConfigurationSource
Description copied from interface:ConfigurationReturns the source of this configuration.- Specified by:
getConfigurationSourcein interfaceConfiguration- Returns:
- the source of this configuration, never
null, but may beConfigurationSource.NULL_SOURCEorConfigurationSource.COMPOSITE_SOURCE
-
getPluginPackages
Description copied from interface:ConfigurationReturns the list of packages to scan for plugins for this Configuration.- Specified by:
getPluginPackagesin interfaceConfiguration- Returns:
- the list of plugin packages.
-
getProperties
- Specified by:
getPropertiesin interfaceConfiguration
-
getScriptManager
- Specified by:
getScriptManagerin interfaceConfiguration
-
setScriptManager
-
getPluginManager
-
setPluginManager
-
getWatchManager
Description copied from interface:ConfigurationReturn the WatchManager.- Specified by:
getWatchManagerin interfaceConfiguration- Returns:
- the WatchManager.
-
getScheduler
- Specified by:
getSchedulerin interfaceConfiguration
-
getRootNode
-
getAsyncLoggerConfigDelegate
Description copied from interface:ConfigurationReturns theAsyncLoggerConfigDelegateshared by allAsyncLoggerConfiginstances defined in this Configuration.- Specified by:
getAsyncLoggerConfigDelegatein interfaceConfiguration- Returns:
- the
AsyncLoggerConfigDelegate
-
getAsyncWaitStrategyFactory
Description copied from interface:ConfigurationReturns theAsyncWaitStrategyFactorydefined in this Configuration; this factory is used to create the LMAX disruptorWaitStrategyused by the disruptor ringbuffer for Async Loggers.- Specified by:
getAsyncWaitStrategyFactoryin interfaceConfiguration- Returns:
- the
AsyncWaitStrategyFactory
-
initialize
public void initialize()Initialize the configuration.- Specified by:
initializein interfaceLifeCycle- Overrides:
initializein classAbstractLifeCycle
-
initializeWatchers
protected void initializeWatchers(Reconfigurable reconfigurable, ConfigurationSource configSource, int monitorIntervalSeconds) -
start
public void start()Start the configuration.- Specified by:
startin interfaceLifeCycle- Overrides:
startin classAbstractFilterable
-
stop
Tear down the configuration.- Specified by:
stopin interfaceLifeCycle2- Overrides:
stopin 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:
isShutdownHookEnabledin interfaceConfiguration
-
getShutdownTimeoutMillis
public long getShutdownTimeoutMillis()- Specified by:
getShutdownTimeoutMillisin interfaceConfiguration
-
setup
public void setup() -
getDefaultStatus
-
createAdvertiser
protected void createAdvertiser(String advertiserString, ConfigurationSource configSource, byte[] buffer, String contentType) -
getComponent
- Specified by:
getComponentin interfaceConfiguration
-
addComponent
- Specified by:
addComponentin interfaceConfiguration
-
preConfigure
-
processConditionals
Process conditions by evaluating them and including the children of conditions that are true and discarding those that are not.- Parameters:
node- The node to evaluate.
-
processSelect
Handle Select nodes. This finds the first child condition that returns true and attaches its children to the parent of the Select Node. Other Nodes are discarded.- Parameters:
selectNode- The Select Node.type- The PluginType of the Select Node.- Returns:
- The list of Nodes to be added to the parent.
-
doConfigure
protected void doConfigure() -
getDefaultLevel
-
setToDefault
protected void setToDefault() -
setName
Set the name of the configuration.- Parameters:
name- The name.
-
getName
Returns the name of the configuration.- Specified by:
getNamein interfaceConfiguration- Returns:
- the name of the configuration.
-
addListener
Add a listener for changes on the configuration.- Specified by:
addListenerin interfaceConfiguration- Parameters:
listener- The ConfigurationListener to add.
-
removeListener
Remove a ConfigurationListener.- Specified by:
removeListenerin interfaceConfiguration- Parameters:
listener- The ConfigurationListener to remove.
-
getAppender
Returns the Appender with the specified name.- Specified by:
getAppenderin 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
Returns a Map containing all the Appenders and their name.- Specified by:
getAppendersin interfaceConfiguration- Returns:
- A Map containing each Appender's name and the Appender object.
-
addAppender
Adds an Appender to the configuration.- Specified by:
addAppenderin interfaceConfiguration- Parameters:
appender- The Appender to add.
-
getStrSubstitutor
- Specified by:
getStrSubstitutorin interfaceConfiguration
-
getConfigurationStrSubstitutor
- Specified by:
getConfigurationStrSubstitutorin interfaceConfiguration
-
setAdvertiser
- Specified by:
setAdvertiserin interfaceConfiguration
-
getAdvertiser
- Specified by:
getAdvertiserin interfaceConfiguration
-
getReliabilityStrategy
- Specified by:
getReliabilityStrategyin interfaceConfiguration
-
addLoggerAppender
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:
addLoggerAppenderin interfaceConfiguration- Parameters:
logger- The Logger the Appender will be associated with.appender- The Appender.
-
addLoggerFilter
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:
addLoggerFilterin interfaceConfiguration- Parameters:
logger- The Logger the Footer will be associated with.filter- The Filter.
-
setLoggerAdditive
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:
setLoggerAdditivein interfaceConfiguration- Parameters:
logger- The Logger the Appender will be associated with.additive- True if the LoggerConfig should be additive, false otherwise.
-
removeAppender
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
Description copied from interface:ConfigurationReturns 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:
getCustomLevelsin interfaceConfiguration- Returns:
- the custom levels defined in the current configuration
-
getLoggerConfig
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:
getLoggerConfigin interfaceConfiguration- Parameters:
loggerName- The Logger name.- Returns:
- The located LoggerConfig.
-
getLoggerContext
Description copied from interface:ConfigurationGets the logger context.- Specified by:
getLoggerContextin interfaceConfiguration- Returns:
- the logger context.
-
getRootLogger
Returns the root Logger.- Specified by:
getRootLoggerin interfaceConfiguration- Returns:
- the root Logger.
-
getLoggers
Returns a Map of all the LoggerConfigs.- Specified by:
getLoggersin interfaceConfiguration- Returns:
- a Map with each entry containing the name of the Logger and the LoggerConfig.
-
getLogger
Returns the LoggerConfig with the specified name.- Parameters:
loggerName- The Logger name.- Returns:
- The LoggerConfig or null if no match was found.
-
addLogger
Add a loggerConfig. The LoggerConfig must already be configured with Appenders, Filters, etc. After addLogger is called LoggerContext.updateLoggers must be called.- Specified by:
addLoggerin interfaceConfiguration- Parameters:
loggerName- The name of the Logger.loggerConfig- The LoggerConfig.
-
removeLogger
Remove a LoggerConfig.- Specified by:
removeLoggerin interfaceConfiguration- Parameters:
loggerName- The name of the Logger.
-
createConfiguration
- Specified by:
createConfigurationin interfaceConfiguration
-
createPluginObject
This method is used by Arbiters to create specific children.- Parameters:
type- The PluginType.node- The Node.- Returns:
- The created object or null;
-
toByteArray
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 thereadmethod of the provided InputStream throws this exception.
-
getNanoClock
Description copied from interface:ConfigurationReturns theNanoClockinstance for this configuration.- Specified by:
getNanoClockin interfaceConfiguration- Returns:
- the nano clock
-
setNanoClock
Description copied from interface:ConfigurationSets theNanoClockinstance for this configuration.- Specified by:
setNanoClockin interfaceConfiguration- Parameters:
nanoClock- the new nano clock for this configuration. Must be non-null.
-