From 5111fd52f2eade90f52c26d7b7b87b7882ac26c5 Mon Sep 17 00:00:00 2001 From: Charles Allen Date: Tue, 2 Feb 2016 15:48:06 -0800 Subject: [PATCH] Add check for log4j-core in Log4jShutterDownerModule --- .../druid/initialization/Log4jShutterDownerModule.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/server/src/main/java/io/druid/initialization/Log4jShutterDownerModule.java b/server/src/main/java/io/druid/initialization/Log4jShutterDownerModule.java index 9b4f2806534..7e98c597346 100644 --- a/server/src/main/java/io/druid/initialization/Log4jShutterDownerModule.java +++ b/server/src/main/java/io/druid/initialization/Log4jShutterDownerModule.java @@ -45,8 +45,15 @@ public class Log4jShutterDownerModule implements Module // This makes the shutdown run pretty darn near last. 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 - 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(); if (!(contextFactory instanceof Log4jContextFactory)) {