Merge pull request #2375 from metamx/moreLog4jChecks

Add check for log4j-core in Log4jShutterDownerModule
This commit is contained in:
Xavier Léauté 2016-02-02 17:06:50 -08:00
commit b90cee5d0d
1 changed files with 8 additions and 1 deletions

View File

@ -45,8 +45,15 @@ public class Log4jShutterDownerModule implements Module
// This makes the shutdown run pretty darn near last. // This makes the shutdown run pretty darn near last.
try { try {
ClassLoader loader = Thread.currentThread().getContextClassLoader();
if(loader == null) {
loader = getClass().getClassLoader();
}
// Reflection to try and allow non Log4j2 stuff to run. This acts as a gateway to stop errors in the next few lines // Reflection to try and allow non Log4j2 stuff to run. This acts as a gateway to stop errors in the next few lines
final Class<?> logManagerClazz = Class.forName("org.apache.logging.log4j.LogManager"); // In log4j api
final Class<?> logManagerClazz = Class.forName("org.apache.logging.log4j.LogManager", false, loader);
// In log4j core
final Class<?> callbackRegistryClazz = Class.forName("org.apache.logging.log4j.core.util.ShutdownCallbackRegistry", false, loader);
final LoggerContextFactory contextFactory = LogManager.getFactory(); final LoggerContextFactory contextFactory = LogManager.getFactory();
if (!(contextFactory instanceof Log4jContextFactory)) { if (!(contextFactory instanceof Log4jContextFactory)) {