Class LoggingUtil


  • public class LoggingUtil
    extends Object
    • Method Detail

      • getLoggerContext

        public static ch.qos.logback.classic.LoggerContext getLoggerContext()
        Acquires the logger context.

        It tries to correctly acquire the logger context in the multi-threaded environment. Because of the http://jira.qos.ch/browse/SLF4J-167 a thread, that didn't start initialization has a possibility to get a reference not to a real context, but to a substitute.

        To work around this bug we spin-loop the thread with a sensible timeout, while the context is not initialized. We can't just make this method synchronized, because LoggerFactory.getILoggerFactory doesn't safely publish own state. Threads can observe a stale state, even if the logger has been already initialized. That's why this method is not thread-safe, but it makes the best effort to return the correct result in the multi-threaded environment.

      • hijackJDKLogging

        public static void hijackJDKLogging()
        Gets the root j.u.l.Logger and removes all registered handlers then redirects all active j.u.l. to SLF4J

        N.B. This should only happen once, hence the flag and locking