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
public abstract class ConfigurationFactory extends ConfigurationBuilderFactory
Factory class for parsedConfigurationobjects 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
ConfigurationFactorycategory. TheOrderannotation should be used to configure the factory to be the first one inspected. See XmlConfigurationFactory for an example.
-
-
Field Summary
Fields Modifier and Type Field Description static StringAUTHORIZATION_PROVIDERstatic StringCATEGORYPlugin category used to inject a ConfigurationFactoryPluginclass.static StringCONFIGURATION_FACTORY_PROPERTYAllows the ConfigurationFactory class to be specified as a system property.static StringCONFIGURATION_FILE_PROPERTYAllows the location of the configuration file to be specified as a system property.protected static StringDEFAULT_PREFIXFile name prefix for standard configurations.static StringLOG4J1_CONFIGURATION_FILE_PROPERTYstatic StringLOG4J1_EXPERIMENTALprotected static StringLOG4J1_VERSIONprotected static StringLOG4J2_VERSIONprotected static LoggerLOGGERAllows subclasses access to the status logger without creating another instance.protected StrSubstitutorsubstitutorprotected static StringTEST_PREFIXFile name prefix for test configurations.
-
Constructor Summary
Constructors Constructor Description ConfigurationFactory()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static AuthorizationProviderauthorizationProvider(PropertiesUtil props)static AuthorizationProvidergetAuthorizationProvider()ConfigurationgetConfiguration(LoggerContext loggerContext, String name, URI configLocation)Returns the Configuration.ConfigurationgetConfiguration(LoggerContext loggerContext, String name, URI configLocation, ClassLoader loader)Returns the Configuration obtained using a given ClassLoader.ConfigurationgetConfiguration(LoggerContext loggerContext, String name, List<URI> configLocations){@return a {@link Configuration} created using provided configuration location {@link URI}s}abstract ConfigurationgetConfiguration(LoggerContext loggerContext, ConfigurationSource source)protected StringgetDefaultPrefix()protected ConfigurationSourcegetInputFromString(String config, ClassLoader loader)Deprecated.static ConfigurationFactorygetInstance()Returns the ConfigurationFactory.protected abstract String[]getSupportedTypes()protected StringgetTestPrefix()protected StringgetVersion()protected booleanisActive()static voidremoveConfigurationFactory(ConfigurationFactory factory)Removes the ConfigurationFactory.static voidresetConfigurationFactory()Resets the ConfigurationFactory to the default.static voidsetConfigurationFactory(ConfigurationFactory factory)Sets the configuration factory.-
Methods inherited from class org.apache.logging.log4j.core.config.builder.api.ConfigurationBuilderFactory
newConfigurationBuilder, newConfigurationBuilder
-
-
-
-
Field Detail
-
CONFIGURATION_FACTORY_PROPERTY
public static final String CONFIGURATION_FACTORY_PROPERTY
Allows the ConfigurationFactory class to be specified as a system property.- See Also:
- Constant Field Values
-
CONFIGURATION_FILE_PROPERTY
public static final String CONFIGURATION_FILE_PROPERTY
Allows the location of the configuration file to be specified as a system property.- See Also:
- Constant Field Values
-
LOG4J1_CONFIGURATION_FILE_PROPERTY
public static final String LOG4J1_CONFIGURATION_FILE_PROPERTY
- See Also:
- Constant Field Values
-
LOG4J1_EXPERIMENTAL
public static final String LOG4J1_EXPERIMENTAL
- See Also:
- Constant Field Values
-
AUTHORIZATION_PROVIDER
public static final String AUTHORIZATION_PROVIDER
- See Also:
- Constant Field Values
-
CATEGORY
public static final String CATEGORY
Plugin category used to inject a ConfigurationFactoryPluginclass.- Since:
- 2.1
- See Also:
- Constant Field Values
-
LOGGER
protected static final Logger LOGGER
Allows subclasses access to the status logger without creating another instance.
-
TEST_PREFIX
protected static final String TEST_PREFIX
File name prefix for test configurations.- See Also:
- Constant Field Values
-
DEFAULT_PREFIX
protected static final String DEFAULT_PREFIX
File name prefix for standard configurations.- See Also:
- Constant Field Values
-
LOG4J1_VERSION
protected static final String LOG4J1_VERSION
- See Also:
- Constant Field Values
-
LOG4J2_VERSION
protected static final String LOG4J2_VERSION
- See Also:
- Constant Field Values
-
substitutor
protected final StrSubstitutor substitutor
-
-
Method Detail
-
getInstance
public static ConfigurationFactory getInstance()
Returns the ConfigurationFactory.- Returns:
- the ConfigurationFactory.
-
authorizationProvider
public static AuthorizationProvider authorizationProvider(PropertiesUtil props)
-
getAuthorizationProvider
public static AuthorizationProvider getAuthorizationProvider()
-
setConfigurationFactory
public static void setConfigurationFactory(ConfigurationFactory factory)
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
public static void removeConfigurationFactory(ConfigurationFactory factory)
Removes the ConfigurationFactory. This method is not intended for general use and may not be thread safe.- Parameters:
factory- The factory to remove.
-
getSupportedTypes
protected abstract String[] getSupportedTypes()
-
getTestPrefix
protected String getTestPrefix()
-
getDefaultPrefix
protected String getDefaultPrefix()
-
getVersion
protected String getVersion()
-
isActive
protected boolean isActive()
-
getConfiguration
public abstract Configuration getConfiguration(LoggerContext loggerContext, ConfigurationSource source)
-
getConfiguration
public Configuration getConfiguration(LoggerContext loggerContext, String name, URI configLocation)
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.
-
getConfiguration
public Configuration getConfiguration(LoggerContext loggerContext, String name, List<URI> configLocations)
{@return a {@link Configuration} created using provided configuration location {@link URI}s}Configurations will be loaded and merged in the given order using the effective merge strategy. The default can be changed using the "log4j.mergeStrategy" system property.
If the provided list of
URIs is empty, the configuration factory attempts to load an implementation-dependent set of default locations. If no configuration can be found, aConfigurationExceptionis thrown.- Parameters:
loggerContext- a logger context, may be nullname- a configuration name, may be nullconfigLocations- configuration locationURIs, may not contain or be null- Throws:
ConfigurationException- if configuration could not be createdNullPointerException- ifconfigLocationscontains or is null- Since:
- 2.26.0
-
getInputFromString
@Deprecated protected ConfigurationSource getInputFromString(String config, ClassLoader loader)
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.
-
-