Class ConfigurationFactory

Direct Known Subclasses:
JsonConfigurationFactory, PropertiesConfigurationFactory, XmlConfigurationFactory, YamlConfigurationFactory

public abstract class ConfigurationFactory extends ConfigurationBuilderFactory
Factory class for parsed Configuration objects from a configuration file. ConfigurationFactory allows the configuration implementation to be dynamically chosen in 1 of 3 ways:
  1. A system property named "log4j.configurationFactory" can be set with the name of the ConfigurationFactory to be used.
  2. setConfigurationFactory(ConfigurationFactory) can be called with the instance of the ConfigurationFactory to be used. This must be called before any other calls to Log4j.
  3. A ConfigurationFactory implementation can be added to the classpath and configured as a plugin in the ConfigurationFactory category. The Order annotation should be used to configure the factory to be the first one inspected. See XmlConfigurationFactory for an example.
If the ConfigurationFactory that was added returns null on a call to getConfiguration then any other ConfigurationFactories found as plugins will be called in their respective order. DefaultConfiguration is always called last if no configuration has been returned.
  • Field Details


      public static final String CONFIGURATION_FACTORY_PROPERTY
      Allows the ConfigurationFactory class to be specified as a system property.
      See Also:

      public static final String CONFIGURATION_FILE_PROPERTY
      Allows the location of the configuration file to be specified as a system property.
      See Also:

      public static final String LOG4J1_CONFIGURATION_FILE_PROPERTY
      See Also:

      public static final String LOG4J1_EXPERIMENTAL
      See Also:

      public static final String AUTHORIZATION_PROVIDER
      See Also:

      public static final String CATEGORY
      Plugin category used to inject a ConfigurationFactory Plugin class.
      See Also:
    • LOGGER

      protected static final Logger LOGGER
      Allows subclasses access to the status logger without creating another instance.

      protected static final String TEST_PREFIX
      File name prefix for test configurations.
      See Also:

      protected static final String DEFAULT_PREFIX
      File name prefix for standard configurations.
      See Also:

      protected static final String LOG4J1_VERSION
      See Also:

      protected static final String LOG4J2_VERSION
      See Also:
    • substitutor

      protected final StrSubstitutor substitutor
  • Constructor Details

    • ConfigurationFactory

      public ConfigurationFactory()
  • Method Details

    • getInstance

      public static ConfigurationFactory getInstance()
      Returns the ConfigurationFactory.
      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.
      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.
      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.
      loggerContext - The logger context
      name - The configuration name.
      configLocation - The configuration location.
      The Configuration.
    • getConfiguration

      public Configuration getConfiguration(LoggerContext loggerContext, String name, URI configLocation, ClassLoader loader)
      Returns the Configuration obtained using a given ClassLoader.
      loggerContext - The logger context
      name - The configuration name.
      configLocation - A URI representing the location of the configuration.
      loader - The default ClassLoader to use. If this is null, then the default ClassLoader will be used.
      The Configuration.
    • getInputFromString

      @Deprecated protected ConfigurationSource getInputFromString(String config, ClassLoader loader)
      Loads the configuration from the location represented by the String.
      config - The configuration location.
      loader - The default ClassLoader to use.
      The InputSource to use to read the configuration.