Class ProviderUtil

java.lang.Object
org.apache.logging.log4j.util.ProviderUtil

@InternalApi public final class ProviderUtil extends Object
Consider this class private.

Utility class for Log4j Providers. When integrating with an application container framework, any Log4j Providers not accessible through standard classpath scanning should loadProvider(java.net.URL, ClassLoader) a classpath accordingly.

  • Field Details

    • PROVIDER_RESOURCE

      static final String PROVIDER_RESOURCE
      Resource name for a Log4j 2 provider properties file.
      See Also:
    • PROVIDERS

      static final Collection<Provider> PROVIDERS
      Loaded providers.
    • STARTUP_LOCK

      static final Lock STARTUP_LOCK
      Guards the ProviderUtil singleton instance from lazy initialization.

      This is primarily used for OSGi support. It allows the OSGi Activator to pause the startup and wait for a Provider to be installed. See LOG4J2-373.

    • COMPATIBLE_API_VERSIONS

      private static final String[] COMPATIBLE_API_VERSIONS
    • LOGGER

      private static final Logger LOGGER
    • PROVIDER

      private static volatile Provider PROVIDER
  • Constructor Details

    • ProviderUtil

      private ProviderUtil()
  • Method Details

    • addProvider

      static void addProvider(Provider provider)
    • loadProvider

      static void loadProvider(URL url, ClassLoader cl)
      Loads an individual Provider implementation. This method is really only useful for the OSGi bundle activator and this class itself.
      Parameters:
      url - the URL to the provider properties file
      cl - the ClassLoader to load the provider classes with
    • loadProviders

      @Deprecated static void loadProviders(Enumeration<URL> urls, ClassLoader cl)
      Deprecated.
      Use loadProvider(java.net.URL, ClassLoader) instead. Will be removed in 3.0.
    • getProvider

      public static Provider getProvider()
      Since:
      2.24.0
    • getProviders

      public static Iterable<Provider> getProviders()
    • hasProviders

      public static boolean hasProviders()
    • lazyInit

      static void lazyInit()
      Lazily initializes the ProviderUtil singleton.

      Note that the following initial call to ProviderUtil may block until a Provider has been installed when running in an OSGi environment.

    • selectProvider

      static Provider selectProvider(PropertiesUtil properties, Collection<Provider> providers, Logger statusLogger)
      Used to test the public getProvider() method.
    • findClassLoader

      public static ClassLoader findClassLoader()
    • validVersion

      private static boolean validVersion(String version)