final org.apache.logging.log4j.spi.LoggerContext context = LogManager.getContext(loader, false, configLocation);
if (context instanceof LoggerContext) {
final LoggerContext ctx = (LoggerContext) context;
ContextAnchor.THREAD_CONTEXT.set(ctx);
final Configuration config = ConfigurationFactory.getInstance().getConfiguration(source);
ctx.start(config);
ContextAnchor.THREAD_CONTEXT.remove();
return ctx;
} else {
LOGGER.error("LogManager returned an instance of {} which does not implement {}. Unable to initialize Log4j",
context.getClass().getName(), LoggerContext.class.getName());