Class ConfigurationFactory
java.lang.Object
org.apache.logging.log4j.core.config.builder.api.ConfigurationBuilderFactory
org.apache.logging.log4j.core.config.ConfigurationFactory
- Direct Known Subclasses:
JsonConfigurationFactory
,PropertiesConfigurationFactory
,XmlConfigurationFactory
,YamlConfigurationFactory
Factory class for parsed
Configuration
objects from a configuration file.
ConfigurationFactory allows the configuration implementation to be
dynamically chosen in 1 of 3 ways:
- A system property named "log4j.configurationFactory" can be set with the name of the ConfigurationFactory to be used.
- setConfigurationFactory(ConfigurationFactory) can be called with the instance of the ConfigurationFactory to be used. This must be called before any other calls to Log4j.
-
A ConfigurationFactory implementation can be added to the classpath and configured as a plugin in the
ConfigurationFactory
category. TheOrder
annotation should be used to configure the factory to be the first one inspected. See XmlConfigurationFactory for an example.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final String
static final String
Plugin category used to inject a ConfigurationFactoryPlugin
class.static final String
Allows the ConfigurationFactory class to be specified as a system property.static final String
Allows the location of the configuration file to be specified as a system property.protected static final String
File name prefix for standard configurations.static final String
static final String
protected static final String
protected static final String
protected static final Logger
Allows subclasses access to the status logger without creating another instance.protected final StrSubstitutor
protected static final String
File name prefix for test configurations. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic AuthorizationProvider
static AuthorizationProvider
getConfiguration
(LoggerContext loggerContext, String name, URI configLocation) Returns the Configuration.getConfiguration
(LoggerContext loggerContext, String name, URI configLocation, ClassLoader loader) Returns the Configuration obtained using a given ClassLoader.abstract Configuration
getConfiguration
(LoggerContext loggerContext, ConfigurationSource source) protected String
protected ConfigurationSource
getInputFromString
(String config, ClassLoader loader) Deprecated.static ConfigurationFactory
Returns the ConfigurationFactory.protected abstract String[]
protected String
protected String
protected boolean
isActive()
static void
Removes the ConfigurationFactory.static void
Resets the ConfigurationFactory to the default.static void
Sets the configuration factory.Methods inherited from class org.apache.logging.log4j.core.config.builder.api.ConfigurationBuilderFactory
newConfigurationBuilder, newConfigurationBuilder
-
Field Details
-
CONFIGURATION_FACTORY_PROPERTY
Allows the ConfigurationFactory class to be specified as a system property.- See Also:
-
CONFIGURATION_FILE_PROPERTY
Allows the location of the configuration file to be specified as a system property.- See Also:
-
LOG4J1_CONFIGURATION_FILE_PROPERTY
- See Also:
-
LOG4J1_EXPERIMENTAL
- See Also:
-
AUTHORIZATION_PROVIDER
- See Also:
-
CATEGORY
Plugin category used to inject a ConfigurationFactoryPlugin
class.- Since:
- 2.1
- See Also:
-
LOGGER
Allows subclasses access to the status logger without creating another instance. -
TEST_PREFIX
File name prefix for test configurations.- See Also:
-
DEFAULT_PREFIX
File name prefix for standard configurations.- See Also:
-
LOG4J1_VERSION
- See Also:
-
LOG4J2_VERSION
- See Also:
-
substitutor
-
-
Constructor Details
-
ConfigurationFactory
public ConfigurationFactory()
-
-
Method Details
-
getInstance
Returns the ConfigurationFactory.- Returns:
- the ConfigurationFactory.
-
authorizationProvider
-
getAuthorizationProvider
-
setConfigurationFactory
Sets the configuration factory. This method is not intended for general use and may not be thread safe.- Parameters:
factory
- the ConfigurationFactory.
-
resetConfigurationFactory
public static void resetConfigurationFactory()Resets the ConfigurationFactory to the default. This method is not intended for general use and may not be thread safe. -
removeConfigurationFactory
Removes the ConfigurationFactory. This method is not intended for general use and may not be thread safe.- Parameters:
factory
- The factory to remove.
-
getSupportedTypes
-
getTestPrefix
-
getDefaultPrefix
-
getVersion
-
isActive
protected boolean isActive() -
getConfiguration
public abstract Configuration getConfiguration(LoggerContext loggerContext, ConfigurationSource source) -
getConfiguration
Returns the Configuration.- Parameters:
loggerContext
- The logger contextname
- The configuration name.configLocation
- The configuration location.- Returns:
- The Configuration.
-
getConfiguration
public Configuration getConfiguration(LoggerContext loggerContext, String name, URI configLocation, ClassLoader loader) Returns the Configuration obtained using a given ClassLoader.- Parameters:
loggerContext
- The logger contextname
- The configuration name.configLocation
- A URI representing the location of the configuration.loader
- The default ClassLoader to use. If this isnull
, then the default ClassLoader will be used.- Returns:
- The Configuration.
-
getInputFromString
Deprecated.Loads the configuration from the location represented by the String.- Parameters:
config
- The configuration location.loader
- The default ClassLoader to use.- Returns:
- The InputSource to use to read the configuration.
-