final LoggerContextFactory contextFactory = LogManager.getFactory(); if (!(contextFactory instanceof Log4jContextFactory)) { log.warn(
@Override protected void before() throws Throwable { this.restoreLoggerContextFactory = LogManager.getFactory(); LogManager.setFactory(this.loggerContextFactory); }
if (result == null && ProviderUtil.hasProviders() && LogManager.getFactory() != null) { //LOG4J2-1658 final String factoryClassName = LogManager.getFactory().getClass().getName(); for (final Provider provider : ProviderUtil.getProviders()) { if (factoryClassName.equals(provider.getClassName())) {
@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))); }
@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); } }
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()); }
public void stop() throws MuleException { MuleContainerBootstrap.dispose(); if (deploymentService != null) { deploymentService.stop(); } if (extensionModelLoaderManager != null) { extensionModelLoaderManager.stop(); } coreExtensionManager.stop(); coreExtensionManager.dispose(); if (serviceManager != null) { serviceManager.stop(); } if (toolingService != null) { toolingService.stop(); } if (LogManager.getFactory() instanceof MuleLog4jContextFactory) { ((MuleLog4jContextFactory) LogManager.getFactory()).dispose(); } if (log4jContextFactory != null) { log4jContextFactory.dispose(); } }
@Test public void disposesLogContextFactory() throws Exception { final LoggerContextFactory originalFactory = LogManager.getFactory(); try { MuleLog4jContextFactory contextFactory = mock(MuleLog4jContextFactory.class); LogManager.setFactory(contextFactory); container.stop(); verify(contextFactory).dispose(); } finally { LogManager.setFactory(originalFactory); } }
@Nullable protected LoggerContextFactory findOriginalFactory() { return LogManager.getFactory(); }
/** * Returns the {@code ContextSelector} of the current {@code Log4jContextFactory}. * * @return the {@code ContextSelector} of the current {@code Log4jContextFactory} */ private static ContextSelector getContextSelector() { final LoggerContextFactory factory = LogManager.getFactory(); if (factory instanceof Log4jContextFactory) { final ContextSelector selector = ((Log4jContextFactory) factory).getSelector(); return selector; } return null; }
private static Log4jContextFactory getFactory() { final LoggerContextFactory factory = LogManager.getFactory(); if (factory instanceof Log4jContextFactory) { return (Log4jContextFactory) factory; } else if (factory != null) { LOGGER.error("LogManager returned an instance of {} which does not implement {}. Unable to initialize Log4j.", factory.getClass().getName(), Log4jContextFactory.class.getName()); return null; } else { LOGGER.fatal("LogManager did not return a LoggerContextFactory. This indicates something has gone terribly wrong!"); return null; } }
public void stop() throws MuleException { coreExtensionManager.stop(); if (deploymentService != null) { deploymentService.stop(); } coreExtensionManager.dispose(); if (LogManager.getFactory() instanceof MuleLog4jContextFactory) { ((MuleLog4jContextFactory) LogManager.getFactory()).dispose(); } }
public void init(final FilterConfig filterConfig) throws ServletException { context = filterConfig.getServletContext(); name = filterConfig.getInitParameter(CONTEXT_NAME); final String configLocn = filterConfig.getInitParameter(CONFIG_LOCATION); if (name == null) { throw new UnavailableException("A context-name attribute is required"); } if (context.getAttribute(Log4jContextListener.LOG4J_CONTEXT_ATTRIBUTE) == null) { LoggerContext ctx; final LoggerContextFactory factory = LogManager.getFactory(); if (factory instanceof Log4jContextFactory) { final ContextSelector sel = ((Log4jContextFactory) factory).getSelector(); if (sel instanceof NamedContextSelector) { selector = (NamedContextSelector) sel; ctx = selector.locateContext(name, configLocn); } else { return; } } else { return; } context.setAttribute(Log4jContextListener.LOG4J_CONTEXT_ATTRIBUTE, ctx); created = true; context.log("Created context for " + name + " using " + ctx.getClass().getClassLoader()); } }
final LoggerContextFactory contextFactory = LogManager.getFactory(); if (!(contextFactory instanceof Log4jContextFactory)) { log.warn(
private void setUpShutdownHook() { if (shutdownCallback == null) { final LoggerContextFactory factory = LogManager.getFactory(); if (factory instanceof ShutdownCallbackRegistry) { LOGGER.debug(SHUTDOWN_HOOK_MARKER, "Shutdown hook enabled. Registering a new one.");
final LoggerContextFactory contextFactory = LogManager.getFactory(); if (!(contextFactory instanceof Log4jContextFactory)) { log.warn(
if (result == null && ProviderUtil.hasProviders() && LogManager.getFactory() != null) { //LOG4J2-1658 final String factoryClassName = LogManager.getFactory().getClass().getName(); for (final Provider provider : ProviderUtil.getProviders()) { if (factoryClassName.equals(provider.getClassName())) {
public void stop() throws MuleException { MuleContainerBootstrap.dispose(); if (deploymentService != null) { deploymentService.stop(); } if (extensionModelLoaderManager != null) { extensionModelLoaderManager.stop(); } coreExtensionManager.stop(); coreExtensionManager.dispose(); if (serviceManager != null) { serviceManager.stop(); } if (toolingService != null) { toolingService.stop(); } if (LogManager.getFactory() instanceof MuleLog4jContextFactory) { ((MuleLog4jContextFactory) LogManager.getFactory()).dispose(); } if (log4jContextFactory != null) { log4jContextFactory.dispose(); } }
LogManager.getFactory().removeContext(this); } finally { configLock.unlock();