Package org.slf4j

Class LoggerFactory


  • public final class LoggerFactory
    extends java.lang.Object
    The LoggerFactory is a utility class producing Loggers for various logging APIs, most notably for log4j, logback and JDK 1.4 logging. Other implementations such as NOPLogger and SimpleLogger are also supported.

    LoggerFactory is essentially a wrapper around an ILoggerFactory instance bound with LoggerFactory at compile time.

    Please note that all methods in LoggerFactory are static.

    • Field Detail

      • NO_STATICLOGGERBINDER_URL

        static final java.lang.String NO_STATICLOGGERBINDER_URL
        See Also:
        Constant Field Values
      • MULTIPLE_BINDINGS_URL

        static final java.lang.String MULTIPLE_BINDINGS_URL
        See Also:
        Constant Field Values
      • SUBSTITUTE_LOGGER_URL

        static final java.lang.String SUBSTITUTE_LOGGER_URL
        See Also:
        Constant Field Values
      • LOGGER_NAME_MISMATCH_URL

        static final java.lang.String LOGGER_NAME_MISMATCH_URL
        See Also:
        Constant Field Values
      • UNSUCCESSFUL_INIT_URL

        static final java.lang.String UNSUCCESSFUL_INIT_URL
        See Also:
        Constant Field Values
      • UNSUCCESSFUL_INIT_MSG

        static final java.lang.String UNSUCCESSFUL_INIT_MSG
        See Also:
        Constant Field Values
      • NOP_FALLBACK_INITIALIZATION

        static final int NOP_FALLBACK_INITIALIZATION
        See Also:
        Constant Field Values
      • INITIALIZATION_STATE

        static volatile int INITIALIZATION_STATE
      • DETECT_LOGGER_NAME_MISMATCH_PROPERTY

        static final java.lang.String DETECT_LOGGER_NAME_MISMATCH_PROPERTY
        See Also:
        Constant Field Values
      • JAVA_VENDOR_PROPERTY

        static final java.lang.String JAVA_VENDOR_PROPERTY
        See Also:
        Constant Field Values
      • DETECT_LOGGER_NAME_MISMATCH

        static boolean DETECT_LOGGER_NAME_MISMATCH
      • API_COMPATIBILITY_LIST

        private static final java.lang.String[] API_COMPATIBILITY_LIST
        It is LoggerFactory's responsibility to track version changes and manage the compatibility list.

        It is assumed that all versions in the 1.6 are mutually compatible.

      • STATIC_LOGGER_BINDER_PATH

        private static java.lang.String STATIC_LOGGER_BINDER_PATH
    • Constructor Detail

      • LoggerFactory

        private LoggerFactory()
    • Method Detail

      • reset

        static void reset()
        Force LoggerFactory to consider itself uninitialized.

        This method is intended to be called by classes (in the same package) for testing purposes. This method is internal. It can be modified, renamed or removed at any time without notice.

        You are strongly discouraged from calling this method in production code.

      • performInitialization

        private static final void performInitialization()
      • messageContainsOrgSlf4jImplStaticLoggerBinder

        private static boolean messageContainsOrgSlf4jImplStaticLoggerBinder​(java.lang.String msg)
      • bind

        private static final void bind()
      • postBindCleanUp

        private static void postBindCleanUp()
      • fixSubstituteLoggers

        private static void fixSubstituteLoggers()
      • failedBinding

        static void failedBinding​(java.lang.Throwable t)
      • replayEvents

        private static void replayEvents()
      • emitReplayOrSubstituionWarning

        private static void emitReplayOrSubstituionWarning​(SubstituteLoggingEvent event,
                                                           int queueSize)
      • emitSubstitutionWarning

        private static void emitSubstitutionWarning()
      • emitReplayWarning

        private static void emitReplayWarning​(int eventCount)
      • versionSanityCheck

        private static final void versionSanityCheck()
      • findPossibleStaticLoggerBinderPathSet

        static java.util.Set<java.net.URL> findPossibleStaticLoggerBinderPathSet()
      • isAmbiguousStaticLoggerBinderPathSet

        private static boolean isAmbiguousStaticLoggerBinderPathSet​(java.util.Set<java.net.URL> binderPathSet)
      • reportMultipleBindingAmbiguity

        private static void reportMultipleBindingAmbiguity​(java.util.Set<java.net.URL> binderPathSet)
        Prints a warning message on the console if multiple bindings were found on the class path. No reporting is done otherwise.
      • isAndroid

        private static boolean isAndroid()
      • reportActualBinding

        private static void reportActualBinding​(java.util.Set<java.net.URL> binderPathSet)
      • getLogger

        public static Logger getLogger​(java.lang.String name)
        Return a logger named according to the name parameter using the statically bound ILoggerFactory instance.
        Parameters:
        name - The name of the logger.
        Returns:
        logger
      • getLogger

        public static Logger getLogger​(java.lang.Class<?> clazz)
        Return a logger named corresponding to the class passed as parameter, using the statically bound ILoggerFactory instance.

        In case the the clazz parameter differs from the name of the caller as computed internally by SLF4J, a logger name mismatch warning will be printed but only if the slf4j.detectLoggerNameMismatch system property is set to true. By default, this property is not set and no warnings will be printed even in case of a logger name mismatch.

        Parameters:
        clazz - the returned logger will be named after clazz
        Returns:
        logger
        See Also:
        Detected logger name mismatch
      • nonMatchingClasses

        private static boolean nonMatchingClasses​(java.lang.Class<?> clazz,
                                                  java.lang.Class<?> autoComputedCallingClass)
      • getILoggerFactory

        public static ILoggerFactory getILoggerFactory()
        Return the ILoggerFactory instance in use.

        ILoggerFactory instance is bound with this class at compile time.

        Returns:
        the ILoggerFactory instance in use