if (this.name == null) {
throw new IllegalStateException("A log4jContextName context parameter is required");
}
LoggerContext context;
final LoggerContextFactory factory = LogManager.getFactory();
if (factory instanceof Log4jContextFactory) {
final ContextSelector selector = ((Log4jContextFactory) factory).getSelector();
if (selector instanceof NamedContextSelector) {
this.namedContextSelector = (NamedContextSelector) selector;
context = this.namedContextSelector.locateContext(this.name, this.servletContext, configLocation);
ContextAnchor.THREAD_CONTEXT.set(context);
if (context.isInitialized()) {
context.start();
}
ContextAnchor.THREAD_CONTEXT.remove();
} else {
// won't it be amusing if the servlet container uses Log4j as its ServletContext logger?
this.servletContext.log("Potential problem: Selector is not an instance of NamedContextSelector.");
return;
}
} else {
this.servletContext.log("Potential problem: Factory is not an instance of Log4jContextFactory.");
return;
}
this.loggerContext = context;
this.servletContext.log("Created logger context for [" + this.name + "] using [" +
context.getClass().getClassLoader() + "].");
}