public abstract class AbstractConfiguration extends AbstractFilterable implements Configuration
AbstractFilterable.Builder<B extends AbstractFilterable.Builder<B>>LifeCycle.State| Modifier and Type | Field and Description |
|---|---|
private java.lang.Object |
advertisement |
private Advertiser |
advertiser
The Advertiser which exposes appender configurations to external systems.
|
private Node |
advertiserNode |
private java.util.concurrent.ConcurrentMap<java.lang.String,Appender> |
appenders |
private AsyncLoggerConfigDisruptor |
asyncLoggerConfigDisruptor |
private static int |
BUF_SIZE |
private java.util.concurrent.ConcurrentMap<java.lang.String,java.lang.Object> |
componentMap |
private ConfigurationScheduler |
configurationScheduler |
private ConfigurationSource |
configurationSource |
private java.util.List<CustomLevelConfig> |
customLevels |
protected boolean |
isShutdownHookEnabled
Shutdown hook is enabled by default.
|
protected java.util.List<ConfigurationListener> |
listeners
Listeners for configuration changes.
|
private java.util.concurrent.ConcurrentMap<java.lang.String,LoggerConfig> |
loggerConfigs |
private java.lang.ref.WeakReference<LoggerContext> |
loggerContext |
private java.lang.String |
name |
private NanoClock |
nanoClock |
protected PluginManager |
pluginManager
The plugin manager.
|
protected java.util.List<java.lang.String> |
pluginPackages
Packages found in configuration "packages" attribute.
|
private java.util.concurrent.ConcurrentMap<java.lang.String,java.lang.String> |
properties |
private LoggerConfig |
root |
protected Node |
rootNode
The root node of the configuration.
|
protected ScriptManager |
scriptManager
The Script manager.
|
protected long |
shutdownTimeoutMillis
Shutdown timeout in milliseconds.
|
private StrSubstitutor |
subst |
private StrLookup |
tempLookup |
private WatchManager |
watchManager |
DEFAULT_STOP_TIMEOUT, DEFAULT_STOP_TIMEUNIT, LOGGERCONTEXT_PROPERTIES| Modifier | Constructor and Description |
|---|---|
protected |
AbstractConfiguration(LoggerContext loggerContext,
ConfigurationSource configurationSource)
Constructor.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addAppender(Appender appender)
Adds an Appender to the configuration.
|
void |
addComponent(java.lang.String componentName,
java.lang.Object obj) |
void |
addListener(ConfigurationListener listener)
Add a listener for changes on the configuration.
|
void |
addLogger(java.lang.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(java.lang.String advertiserString,
ConfigurationSource configSource,
byte[] buffer,
java.lang.String contentType) |
void |
createConfiguration(Node node,
LogEvent event) |
private static java.util.Collection<?> |
createPluginCollection(Node node) |
private static java.util.Map<java.lang.String,?> |
createPluginMap(Node node) |
private java.lang.Object |
createPluginObject(PluginType<?> type,
Node node,
LogEvent event)
Invokes a static factory method to either create the desired object or to create a builder object that creates
the desired object.
|
protected void |
doConfigure() |
Advertiser |
getAdvertiser() |
<T extends Appender> |
getAppender(java.lang.String appenderName)
Returns the Appender with the specified name.
|
java.util.Map<java.lang.String,Appender> |
getAppenders()
Returns a Map containing all the Appenders and their name.
|
private java.util.List<Appender> |
getAsyncAppenders(Appender[] all) |
AsyncLoggerConfigDelegate |
getAsyncLoggerConfigDelegate()
Returns the
AsyncLoggerConfigDelegate shared by all
AsyncLoggerConfig instances defined in this Configuration. |
<T> T |
getComponent(java.lang.String componentName) |
ConfigurationSource |
getConfigurationSource()
Returns the source of this configuration.
|
java.util.List<CustomLevelConfig> |
getCustomLevels()
Returns a list of descriptors of the custom levels defined in the current configuration.
|
protected Level |
getDefaultStatus() |
LoggerConfig |
getLogger(java.lang.String loggerName)
Returns the LoggerConfig with the specified name.
|
LoggerConfig |
getLoggerConfig(java.lang.String loggerName)
Locates the appropriate LoggerConfig for a Logger name.
|
LoggerContext |
getLoggerContext()
Gets the logger context.
|
java.util.Map<java.lang.String,LoggerConfig> |
getLoggers()
Returns a Map of all the LoggerConfigs.
|
java.lang.String |
getName()
Returns the name of the configuration.
|
NanoClock |
getNanoClock()
Returns the
NanoClock instance for this configuration. |
PluginManager |
getPluginManager() |
java.util.List<java.lang.String> |
getPluginPackages()
Returns the list of packages to scan for plugins for this Configuration.
|
java.util.Map<java.lang.String,java.lang.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.
|
private boolean |
hasAsyncLoggers() |
void |
initialize()
Initialize the configuration.
|
boolean |
isShutdownHookEnabled() |
protected void |
preConfigure(Node node) |
void |
removeAppender(java.lang.String appenderName)
Remove an Appender.
|
void |
removeListener(ConfigurationListener listener)
Remove a ConfigurationListener.
|
void |
removeLogger(java.lang.String loggerName)
Remove a LoggerConfig.
|
void |
setAdvertiser(Advertiser advertiser) |
void |
setLoggerAdditive(Logger logger,
boolean additive)
Marks a LoggerConfig as additive.
|
void |
setName(java.lang.String name)
Set the name of the configuration.
|
void |
setNanoClock(NanoClock nanoClock)
Sets the
NanoClock instance for this configuration. |
private void |
setParents() |
void |
setPluginManager(PluginManager pluginManager) |
void |
setScriptManager(ScriptManager scriptManager) |
protected void |
setToDefault() |
void |
setup() |
private void |
setupAdvertisement() |
void |
start()
Start the configuration.
|
boolean |
stop(long timeout,
java.util.concurrent.TimeUnit timeUnit)
Tear down the configuration.
|
protected static byte[] |
toByteArray(java.io.InputStream is)
Reads an InputStream using buffered reads into a byte array buffer.
|
addFilter, getFilter, hasFilter, isFiltered, removeFilter, stopequalsImpl, getState, getStatusLogger, hashCodeImpl, isInitialized, isStarted, isStarting, isStopped, isStopping, setStarted, setStarting, setState, setStopped, setStopping, stop, stopclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitaddFilter, getFilter, hasFilter, isFiltered, removeFilterprivate static final int BUF_SIZE
protected Node rootNode
protected final java.util.List<ConfigurationListener> listeners
protected final java.util.List<java.lang.String> pluginPackages
protected PluginManager pluginManager
protected boolean isShutdownHookEnabled
protected long shutdownTimeoutMillis
protected ScriptManager scriptManager
private Advertiser advertiser
private Node advertiserNode
private java.lang.Object advertisement
private java.lang.String name
private java.util.concurrent.ConcurrentMap<java.lang.String,Appender> appenders
private java.util.concurrent.ConcurrentMap<java.lang.String,LoggerConfig> loggerConfigs
private java.util.List<CustomLevelConfig> customLevels
private final java.util.concurrent.ConcurrentMap<java.lang.String,java.lang.String> properties
private final StrLookup tempLookup
private final StrSubstitutor subst
private LoggerConfig root
private final java.util.concurrent.ConcurrentMap<java.lang.String,java.lang.Object> componentMap
private final ConfigurationSource configurationSource
private final ConfigurationScheduler configurationScheduler
private final WatchManager watchManager
private AsyncLoggerConfigDisruptor asyncLoggerConfigDisruptor
private NanoClock nanoClock
private final java.lang.ref.WeakReference<LoggerContext> loggerContext
protected AbstractConfiguration(LoggerContext loggerContext, ConfigurationSource configurationSource)
public ConfigurationSource getConfigurationSource()
ConfigurationgetConfigurationSource in interface Configurationpublic java.util.List<java.lang.String> getPluginPackages()
ConfigurationgetPluginPackages in interface Configurationpublic java.util.Map<java.lang.String,java.lang.String> getProperties()
getProperties in interface Configurationpublic ScriptManager getScriptManager()
getScriptManager in interface Configurationpublic void setScriptManager(ScriptManager scriptManager)
public PluginManager getPluginManager()
public void setPluginManager(PluginManager pluginManager)
public WatchManager getWatchManager()
ConfigurationgetWatchManager in interface Configurationpublic ConfigurationScheduler getScheduler()
getScheduler in interface Configurationpublic Node getRootNode()
public AsyncLoggerConfigDelegate getAsyncLoggerConfigDelegate()
ConfigurationAsyncLoggerConfigDelegate shared by all
AsyncLoggerConfig instances defined in this Configuration.getAsyncLoggerConfigDelegate in interface ConfigurationAsyncLoggerConfigDelegatepublic void initialize()
initialize in interface LifeCycleinitialize in class AbstractLifeCyclepublic void start()
start in interface LifeCyclestart in class AbstractFilterableprivate boolean hasAsyncLoggers()
public boolean stop(long timeout,
java.util.concurrent.TimeUnit timeUnit)
stop in interface LifeCycle2stop in class AbstractFilterabletimeout - the maximum time to waittimeUnit - the time unit of the timeout argumentpublic boolean isShutdownHookEnabled()
isShutdownHookEnabled in interface Configurationpublic long getShutdownTimeoutMillis()
getShutdownTimeoutMillis in interface Configurationpublic void setup()
protected Level getDefaultStatus()
protected void createAdvertiser(java.lang.String advertiserString,
ConfigurationSource configSource,
byte[] buffer,
java.lang.String contentType)
private void setupAdvertisement()
public <T> T getComponent(java.lang.String componentName)
getComponent in interface Configurationpublic void addComponent(java.lang.String componentName,
java.lang.Object obj)
addComponent in interface Configurationprotected void preConfigure(Node node)
protected void doConfigure()
protected void setToDefault()
public void setName(java.lang.String name)
name - The name.public java.lang.String getName()
getName in interface Configurationpublic void addListener(ConfigurationListener listener)
addListener in interface Configurationlistener - The ConfigurationListener to add.public void removeListener(ConfigurationListener listener)
removeListener in interface Configurationlistener - The ConfigurationListener to remove.public <T extends Appender> T getAppender(java.lang.String appenderName)
getAppender in interface ConfigurationT - The expected Appender type.appenderName - The name of the Appender.public java.util.Map<java.lang.String,Appender> getAppenders()
getAppenders in interface Configurationpublic void addAppender(Appender appender)
addAppender in interface Configurationappender - The Appender to add.public StrSubstitutor getStrSubstitutor()
getStrSubstitutor in interface Configurationpublic void setAdvertiser(Advertiser advertiser)
setAdvertiser in interface Configurationpublic Advertiser getAdvertiser()
getAdvertiser in interface Configurationpublic ReliabilityStrategy getReliabilityStrategy(LoggerConfig loggerConfig)
getReliabilityStrategy in interface Configurationpublic void addLoggerAppender(Logger logger, Appender appender)
addLoggerAppender in interface Configurationlogger - The Logger the Appender will be associated with.appender - The Appender.public void addLoggerFilter(Logger logger, Filter filter)
addLoggerFilter in interface Configurationlogger - The Logger the Footer will be associated with.filter - The Filter.public void setLoggerAdditive(Logger logger, boolean additive)
setLoggerAdditive in interface Configurationlogger - The Logger the Appender will be associated with.additive - True if the LoggerConfig should be additive, false otherwise.public void removeAppender(java.lang.String appenderName)
appenderName - the name of the appender to remove.public java.util.List<CustomLevelConfig> getCustomLevels()
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}.
getCustomLevels in interface Configurationpublic LoggerConfig getLoggerConfig(java.lang.String loggerName)
getLoggerConfig in interface ConfigurationloggerName - The Logger name.public LoggerContext getLoggerContext()
ConfigurationgetLoggerContext in interface Configurationpublic LoggerConfig getRootLogger()
getRootLogger in interface Configurationpublic java.util.Map<java.lang.String,LoggerConfig> getLoggers()
getLoggers in interface Configurationpublic LoggerConfig getLogger(java.lang.String loggerName)
loggerName - The Logger name.public void addLogger(java.lang.String loggerName,
LoggerConfig loggerConfig)
addLogger in interface ConfigurationloggerName - The name of the Logger.loggerConfig - The LoggerConfig.public void removeLogger(java.lang.String loggerName)
removeLogger in interface ConfigurationloggerName - The name of the Logger.public void createConfiguration(Node node, LogEvent event)
createConfiguration in interface Configurationprivate java.lang.Object createPluginObject(PluginType<?> type, Node node, LogEvent event)
PluginFactory, and each parameter should be annotated with
an appropriate plugin annotation depending on what that parameter describes. Parameters annotated with
PluginAttribute must be a type that can be converted from a
string using one of the TypeConverters
. Parameters with PluginElement may be any plugin class or
an array of a plugin class. Collections and Maps are currently not supported, although the factory method that is
called can create these from an array.
Plugins can also be created using a builder class that implements
Builder. In that case, a static method annotated with
PluginBuilderAttribute should create the builder class, and
the various fields in the builder class should be annotated similarly to the method parameters. However, instead
of using PluginAttribute, one should use
PluginBuilderAttribute where the default value can be
specified as the default field value instead of as an additional annotation parameter.
In either case, there are also annotations for specifying a
Configuration (
PluginConfiguration) or a
Node (
PluginNode).
Although the happy path works, more work still needs to be done to log incorrect parameters. These will generally
result in unhelpful InvocationTargetExceptions.type - the type of plugin to create.node - the corresponding configuration node for this plugin to create.event - the LogEvent that spurred the creation of this pluginnull if there was an error setting it up.PluginBuilder,
PluginVisitor,
TypeConverterprivate static java.util.Map<java.lang.String,?> createPluginMap(Node node)
private static java.util.Collection<?> createPluginCollection(Node node)
private void setParents()
protected static byte[] toByteArray(java.io.InputStream is)
throws java.io.IOException
is - the InputStream to read into a byte array buffer.java.io.IOException - if the read method of the provided InputStream throws this exception.public NanoClock getNanoClock()
ConfigurationNanoClock instance for this configuration.getNanoClock in interface Configurationpublic void setNanoClock(NanoClock nanoClock)
ConfigurationNanoClock instance for this configuration.setNanoClock in interface ConfigurationnanoClock - the new nano clock for this configuration. Must be non-null.