Class Provider

  • Direct Known Subclasses:
    JULProvider, Log4jProvider, SimpleProvider, SLF4JProvider

    @NullMarked
    public class Provider
    extends java.lang.Object
    Service class used to bind the Log4j API with an implementation.

    Implementors should register an implementation of this class with ServiceLoader.

    Deprecated: the automatic registration of providers from META-INF/log4j-provider.properties is supported for compatibility reasons. Support for this file will be dropped in a future version.

    • Field Detail

      • CURRENT_VERSION

        protected static final java.lang.String CURRENT_VERSION
        Constant inlined by the compiler
        Since:
        2.24.0
        See Also:
        Constant Field Values
      • FACTORY_PRIORITY

        @Deprecated
        public static final java.lang.String FACTORY_PRIORITY
        Deprecated.
        since 2.24.0
        Property name to set for a Log4j 2 provider to specify the priority of this implementation.
        Since:
        2.0.1
        See Also:
        Constant Field Values
      • THREAD_CONTEXT_MAP

        @Deprecated
        public static final java.lang.String THREAD_CONTEXT_MAP
        Deprecated.
        since 2.24.0
        Property name to set to the implementation of ThreadContextMap.
        Since:
        2.0.1
        See Also:
        Constant Field Values
      • LOGGER_CONTEXT_FACTORY

        @Deprecated
        public static final java.lang.String LOGGER_CONTEXT_FACTORY
        Deprecated.
        since 2.24.0
        Property name to set to the implementation of LoggerContextFactory.
        Since:
        2.0.1
        See Also:
        Constant Field Values
      • PROVIDER_PROPERTY_NAME

        public static final java.lang.String PROVIDER_PROPERTY_NAME
        System property used to specify the class name of the provider to use.
        Since:
        2.24.0
        See Also:
        Constant Field Values
      • DISABLE_CONTEXT_MAP

        private static final java.lang.String DISABLE_CONTEXT_MAP
        See Also:
        Constant Field Values
      • DISABLE_THREAD_CONTEXT

        private static final java.lang.String DISABLE_THREAD_CONTEXT
        See Also:
        Constant Field Values
      • LOGGER

        private static final Logger LOGGER
      • priority

        private final int priority
      • className

        @Deprecated
        private final @Nullable java.lang.String className
        Deprecated.
      • loggerContextFactoryClass

        private final @Nullable java.lang.Class<? extends LoggerContextFactory> loggerContextFactoryClass
      • threadContextMap

        @Deprecated
        private final @Nullable java.lang.String threadContextMap
        Deprecated.
      • threadContextMapClass

        private final @Nullable java.lang.Class<? extends ThreadContextMap> threadContextMapClass
      • versions

        private final @Nullable java.lang.String versions
      • url

        @Deprecated
        private final @Nullable java.net.URL url
        Deprecated.
      • classLoader

        @Deprecated
        private final java.lang.ref.WeakReference<java.lang.ClassLoader> classLoader
        Deprecated.
    • Constructor Detail

      • Provider

        @Deprecated
        public Provider​(java.util.Properties props,
                        java.net.URL url,
                        java.lang.ClassLoader classLoader)
        Deprecated.
        since 2.24.0
        Constructor used by the deprecated META-INF/log4j-provider.properties format.
        Since:
        2.0.1
      • Provider

        public Provider​(@Nullable java.lang.Integer priority,
                        java.lang.String versions)
        Parameters:
        priority - A positive number specifying the provider's priority or null if default,
        versions - Minimal API version required, should be set to CURRENT_VERSION.
        Since:
        2.24.0
      • Provider

        public Provider​(@Nullable java.lang.Integer priority,
                        java.lang.String versions,
                        @Nullable java.lang.Class<? extends LoggerContextFactory> loggerContextFactoryClass)
        Parameters:
        priority - A positive number specifying the provider's priority or null if default,
        versions - Minimal API version required, should be set to CURRENT_VERSION,
        loggerContextFactoryClass - A public exported implementation of LoggerContextFactory or null if getLoggerContextFactory() is also implemented.
        Since:
        2.9.0
      • Provider

        public Provider​(@Nullable java.lang.Integer priority,
                        java.lang.String versions,
                        @Nullable java.lang.Class<? extends LoggerContextFactory> loggerContextFactoryClass,
                        @Nullable java.lang.Class<? extends ThreadContextMap> threadContextMapClass)
        Parameters:
        priority - A positive number specifying the provider's priority or null if default,
        versions - Minimal API version required, should be set to CURRENT_VERSION,
        loggerContextFactoryClass - A public exported implementation of LoggerContextFactory or null if getLoggerContextFactory() is also implemented,
        threadContextMapClass - A public exported implementation of ThreadContextMap or null if getThreadContextMapInstance() is implemented.
        Since:
        2.9.0
    • Method Detail

      • getVersions

        public java.lang.String getVersions()
        Returns the Log4j API versions supported by the implementation.
        Returns:
        A String containing the Log4j versions supported.
        Since:
        2.9.0
      • getPriority

        public java.lang.Integer getPriority()
        Gets the priority (natural ordering) of this Provider.

        Log4j selects the highest priority provider.

        Returns:
        the priority of this Provider
      • getClassName

        public @Nullable java.lang.String getClassName()
        Gets the class name of the LoggerContextFactory implementation of this Provider.
        Returns:
        the class name of a LoggerContextFactory implementation or null if unspecified.
        See Also:
        loadLoggerContextFactory()
      • loadLoggerContextFactory

        public @Nullable java.lang.Class<? extends LoggerContextFactory> loadLoggerContextFactory()
        Loads the LoggerContextFactory class specified by this Provider.
        Returns:
        the LoggerContextFactory implementation class or null if unspecified or a loader error occurred.
        Since:
        2.0.1
      • getLoggerContextFactory

        public LoggerContextFactory getLoggerContextFactory()
        Returns:
        The logger context factory to be used by LogManager.
        Since:
        2.24.0
      • getThreadContextMap

        public @Nullable java.lang.String getThreadContextMap()
        Gets the class name of the ThreadContextMap implementation of this Provider.
        Returns:
        the class name of a ThreadContextMap implementation
      • loadThreadContextMap

        public @Nullable java.lang.Class<? extends ThreadContextMap> loadThreadContextMap()
        Loads the ThreadContextMap class specified by this Provider.
        Returns:
        the ThreadContextMap implementation class or null if unspecified or a loading error occurred.
        Since:
        2.0.1
      • getThreadContextMapInstance

        public ThreadContextMap getThreadContextMapInstance()
        Returns:
        The thread context map to be used by ThreadContext.
        Since:
        2.24.0
      • getUrl

        @Deprecated
        public @Nullable java.net.URL getUrl()
        Deprecated.
        since 2.24.0, without a replacement.
        Gets the URL containing this Provider's Log4j details.
        Returns:
        the URL corresponding to the Provider META-INF/log4j-provider.properties file or null for a provider class.
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • equals

        public boolean equals​(java.lang.Object o)
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object