public class LoggingUtil extends Object
Modifier and Type | Method and Description |
---|---|
static ch.qos.logback.classic.LoggerContext |
getLoggerContext()
Acquires the logger context.
|
static void |
hijackJDKLogging()
Gets the root j.u.l.Logger and removes all registered handlers
then redirects all active j.u.l.
|
public static ch.qos.logback.classic.LoggerContext getLoggerContext()
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.
public static void hijackJDKLogging()
Copyright © 2019. All rights reserved.