Class ConfigurationFactory
- java.lang.Object
-
- org.apache.logging.log4j.core.config.builder.api.ConfigurationBuilderFactory
-
- org.apache.logging.log4j.core.config.ConfigurationFactory
-
- Direct Known Subclasses:
ConfigurationFactory.Factory,JsonConfigurationFactory,Log4j1ConfigurationFactory,PropertiesConfigurationFactory,PropertiesConfigurationFactory,XmlConfigurationFactory,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.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static classConfigurationFactory.FactoryDefault Factory.
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringAUTHORIZATION_PROVIDERprivate static AuthorizationProviderauthorizationProviderstatic java.lang.StringCATEGORYPlugin category used to inject a ConfigurationFactoryPluginclass.private static java.lang.StringCLASS_LOADER_SCHEMEThe name of the classloader URI scheme.private static java.lang.StringCLASS_PATH_SCHEMEThe name of the classpath URI scheme, synonymous with the classloader URI scheme.private static ConfigurationFactoryconfigFactorystatic java.lang.StringCONFIGURATION_FACTORY_PROPERTYAllows the ConfigurationFactory class to be specified as a system property.static java.lang.StringCONFIGURATION_FILE_PROPERTYAllows the location of the configuration file to be specified as a system property.protected static java.lang.StringDEFAULT_PREFIXFile name prefix for standard configurations.private static java.util.List<ConfigurationFactory>factoriesprivate static java.lang.StringHTTPprivate static java.lang.StringHTTPSprivate static java.util.concurrent.locks.LockLOCKstatic java.lang.StringLOG4J1_CONFIGURATION_FILE_PROPERTYstatic java.lang.StringLOG4J1_EXPERIMENTALprotected static java.lang.StringLOG4J1_VERSIONprotected static java.lang.StringLOG4J2_VERSIONprotected static LoggerLOGGERAllows subclasses access to the status logger without creating another instance.private static java.lang.StringOVERRIDE_PARAMprivate static java.lang.String[]PREFIXESprotected StrSubstitutorsubstitutorprotected static java.lang.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 private static voidaddFactory(java.util.Collection<ConfigurationFactory> list, java.lang.Class<? extends ConfigurationFactory> factoryClass)private static voidaddFactory(java.util.Collection<ConfigurationFactory> list, java.lang.String factoryClass)static AuthorizationProviderauthorizationProvider(PropertiesUtil props)(package private) static java.lang.StringextractClassLoaderUriPath(java.net.URI uri)static AuthorizationProvidergetAuthorizationProvider()ConfigurationgetConfiguration(LoggerContext loggerContext, java.lang.String name, java.net.URI configLocation)Returns the Configuration.ConfigurationgetConfiguration(LoggerContext loggerContext, java.lang.String name, java.net.URI configLocation, java.lang.ClassLoader loader)Returns the Configuration obtained using a given ClassLoader.abstract ConfigurationgetConfiguration(LoggerContext loggerContext, ConfigurationSource source)protected java.lang.StringgetDefaultPrefix()(package private) static java.util.List<ConfigurationFactory>getFactories()protected ConfigurationSourcegetInputFromString(java.lang.String config, java.lang.ClassLoader loader)Deprecated.static ConfigurationFactorygetInstance()Returns the ConfigurationFactory.protected abstract java.lang.String[]getSupportedTypes()protected java.lang.StringgetTestPrefix()protected java.lang.StringgetVersion()protected booleanisActive()(package private) static booleanisClassLoaderUri(java.net.URI uri)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 java.lang.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 java.lang.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 java.lang.String LOG4J1_CONFIGURATION_FILE_PROPERTY
- See Also:
- Constant Field Values
-
LOG4J1_EXPERIMENTAL
public static final java.lang.String LOG4J1_EXPERIMENTAL
- See Also:
- Constant Field Values
-
AUTHORIZATION_PROVIDER
public static final java.lang.String AUTHORIZATION_PROVIDER
- See Also:
- Constant Field Values
-
CATEGORY
public static final java.lang.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 java.lang.String TEST_PREFIX
File name prefix for test configurations.- See Also:
- Constant Field Values
-
DEFAULT_PREFIX
protected static final java.lang.String DEFAULT_PREFIX
File name prefix for standard configurations.- See Also:
- Constant Field Values
-
LOG4J1_VERSION
protected static final java.lang.String LOG4J1_VERSION
- See Also:
- Constant Field Values
-
LOG4J2_VERSION
protected static final java.lang.String LOG4J2_VERSION
- See Also:
- Constant Field Values
-
CLASS_LOADER_SCHEME
private static final java.lang.String CLASS_LOADER_SCHEME
The name of the classloader URI scheme.- See Also:
- Constant Field Values
-
CLASS_PATH_SCHEME
private static final java.lang.String CLASS_PATH_SCHEME
The name of the classpath URI scheme, synonymous with the classloader URI scheme.- See Also:
- Constant Field Values
-
OVERRIDE_PARAM
private static final java.lang.String OVERRIDE_PARAM
- See Also:
- Constant Field Values
-
factories
private static volatile java.util.List<ConfigurationFactory> factories
-
configFactory
private static ConfigurationFactory configFactory
-
substitutor
protected final StrSubstitutor substitutor
-
LOCK
private static final java.util.concurrent.locks.Lock LOCK
-
HTTPS
private static final java.lang.String HTTPS
- See Also:
- Constant Field Values
-
HTTP
private static final java.lang.String HTTP
- See Also:
- Constant Field Values
-
PREFIXES
private static final java.lang.String[] PREFIXES
-
authorizationProvider
private static volatile AuthorizationProvider authorizationProvider
-
-
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()
-
addFactory
private static void addFactory(java.util.Collection<ConfigurationFactory> list, java.lang.String factoryClass)
-
addFactory
private static void addFactory(java.util.Collection<ConfigurationFactory> list, java.lang.Class<? extends ConfigurationFactory> factoryClass)
-
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 java.lang.String[] getSupportedTypes()
-
getTestPrefix
protected java.lang.String getTestPrefix()
-
getDefaultPrefix
protected java.lang.String getDefaultPrefix()
-
getVersion
protected java.lang.String getVersion()
-
isActive
protected boolean isActive()
-
getConfiguration
public abstract Configuration getConfiguration(LoggerContext loggerContext, ConfigurationSource source)
-
getConfiguration
public Configuration getConfiguration(LoggerContext loggerContext, java.lang.String name, java.net.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, java.lang.String name, java.net.URI configLocation, java.lang.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.
-
isClassLoaderUri
static boolean isClassLoaderUri(java.net.URI uri)
-
extractClassLoaderUriPath
static java.lang.String extractClassLoaderUriPath(java.net.URI uri)
-
getInputFromString
@Deprecated protected ConfigurationSource getInputFromString(java.lang.String config, java.lang.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.
-
getFactories
static java.util.List<ConfigurationFactory> getFactories()
-
-