Class ProviderUtil


  • @InternalApi
    public final class ProviderUtil
    extends java.lang.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 Detail

      • PROVIDER_RESOURCE

        static final java.lang.String PROVIDER_RESOURCE
        Resource name for a Log4j 2 provider properties file.
        See Also:
        Constant Field Values
      • PROVIDERS

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

        static final java.util.concurrent.locks.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 java.lang.String[] COMPATIBLE_API_VERSIONS
      • LOGGER

        private static final Logger LOGGER
      • PROVIDER

        private static volatile Provider PROVIDER
    • Constructor Detail

      • ProviderUtil

        private ProviderUtil()
    • Method Detail

      • addProvider

        static void addProvider​(Provider provider)
      • loadProvider

        static void loadProvider​(java.net.URL url,
                                 java.lang.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​(java.util.Enumeration<java.net.URL> urls,
                                  java.lang.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 java.lang.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.

      • findClassLoader

        public static java.lang.ClassLoader findClassLoader()
      • validVersion

        private static boolean validVersion​(java.lang.String version)