use of org.apache.logging.log4j.core.selector.ContextSelector in project hive by apache.
the class TestHiveAsyncLogging method testAsyncLoggingInitialization.
// this test requires disruptor jar in classpath
@Test
public void testAsyncLoggingInitialization() throws Exception {
HiveConf conf = new HiveConf();
conf.setBoolVar(ConfVars.HIVE_ASYNC_LOG_ENABLED, false);
LogUtils.initHiveLog4jCommon(conf, ConfVars.HIVE_LOG4J_FILE);
Log4jContextFactory log4jContextFactory = (Log4jContextFactory) LogManager.getFactory();
ContextSelector contextSelector = log4jContextFactory.getSelector();
assertTrue(contextSelector instanceof ClassLoaderContextSelector);
conf.setBoolVar(ConfVars.HIVE_ASYNC_LOG_ENABLED, true);
LogUtils.initHiveLog4jCommon(conf, ConfVars.HIVE_LOG4J_FILE);
log4jContextFactory = (Log4jContextFactory) LogManager.getFactory();
contextSelector = log4jContextFactory.getSelector();
assertTrue(contextSelector instanceof AsyncLoggerContextSelector);
}
use of org.apache.logging.log4j.core.selector.ContextSelector in project logging-log4j2 by apache.
the class ShutdownCallbackRegistryTest method testShutdownCallbackRegistry.
@Test
public void testShutdownCallbackRegistry() throws Exception {
final LoggerContext context = ctx.getLoggerContext();
assertTrue("LoggerContext should be started", context.isStarted());
assertThat(Registry.CALLBACKS, hasSize(1));
Registry.shutdown();
assertTrue("LoggerContext should be stopped", context.isStopped());
assertThat(Registry.CALLBACKS, hasSize(0));
final ContextSelector selector = ((Log4jContextFactory) LogManager.getFactory()).getSelector();
assertThat(selector.getLoggerContexts(), not(hasItem(context)));
}
use of org.apache.logging.log4j.core.selector.ContextSelector in project logging-log4j2 by apache.
the class Server method reregisterMBeansAfterReconfigure.
public static void reregisterMBeansAfterReconfigure(final MBeanServer mbs) {
if (isJmxDisabled()) {
LOGGER.debug("JMX disabled for Log4j2. Not registering MBeans.");
return;
}
// LoggerConfigs and Appenders
try {
final ContextSelector selector = getContextSelector();
if (selector == null) {
LOGGER.debug("Could not register MBeans: no ContextSelector found.");
return;
}
LOGGER.trace("Reregistering MBeans after reconfigure. Selector={}", selector);
final List<LoggerContext> contexts = selector.getLoggerContexts();
int i = 0;
for (final LoggerContext ctx : contexts) {
LOGGER.trace("Reregistering context ({}/{}): '{}' {}", ++i, contexts.size(), ctx.getName(), ctx);
// first unregister the context and all nested loggers,
// appenders, statusLogger, contextSelector, ringbuffers...
unregisterLoggerContext(ctx.getName(), mbs);
final LoggerContextAdmin mbean = new LoggerContextAdmin(ctx, executor);
register(mbs, mbean, mbean.getObjectName());
if (ctx instanceof AsyncLoggerContext) {
final RingBufferAdmin rbmbean = ((AsyncLoggerContext) ctx).createRingBufferAdmin();
if (rbmbean.getBufferSize() > 0) {
// don't register if Disruptor not started (DefaultConfiguration: config not found)
register(mbs, rbmbean, rbmbean.getObjectName());
}
}
// register the status logger and the context selector
// repeatedly
// for each known context: if one context is unregistered,
// these MBeans should still be available for the other
// contexts.
registerStatusLogger(ctx.getName(), mbs, executor);
registerContextSelector(ctx.getName(), selector, mbs, executor);
registerLoggerConfigs(ctx, mbs, executor);
registerAppenders(ctx, mbs, executor);
}
} catch (final Exception ex) {
LOGGER.error("Could not register mbeans", ex);
}
}
use of org.apache.logging.log4j.core.selector.ContextSelector in project logging-log4j2 by apache.
the class Log4jWebInitializerImpl method initializeJndi.
private void initializeJndi(final String location) {
final URI configLocation = getConfigURI(location);
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 {
LOGGER.warn("Potential problem: Selector is not an instance of NamedContextSelector.");
return;
}
} else {
LOGGER.warn("Potential problem: LoggerContextFactory is not an instance of Log4jContextFactory.");
return;
}
this.loggerContext = context;
LOGGER.debug("Created logger context for [{}] using [{}].", this.name, context.getClass().getClassLoader());
}
Aggregations