org.apache.logging.log4j.LogManager.getFactory()方法的使用及代码示例

x33g5p2x  于2022-01-23 转载在 其他  
字(8.5k)|赞(0)|评价(0)|浏览(116)

本文整理了Java中org.apache.logging.log4j.LogManager.getFactory()方法的一些代码示例,展示了LogManager.getFactory()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。LogManager.getFactory()方法的具体详情如下:
包路径:org.apache.logging.log4j.LogManager
类名称:LogManager
方法名:getFactory

LogManager.getFactory介绍

[英]Returns the current LoggerContextFactory.
[中]返回当前LoggerContextFactory。

代码示例

代码示例来源:origin: apache/incubator-druid

final LoggerContextFactory contextFactory = LogManager.getFactory();
if (!(contextFactory instanceof Log4jContextFactory)) {
 log.warn(

代码示例来源:origin: org.apache.logging.log4j/log4j-api

@Override
protected void before() throws Throwable {
  this.restoreLoggerContextFactory = LogManager.getFactory();
  LogManager.setFactory(this.loggerContextFactory);
}

代码示例来源:origin: org.apache.logging.log4j/log4j-api

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())) {

代码示例来源:origin: org.apache.logging.log4j/log4j-core

@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)));
}

代码示例来源:origin: apache/hive

@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);
 }
}

代码示例来源:origin: org.apache.logging.log4j/log4j-web

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());
}

代码示例来源:origin: mulesoft/mule

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();
 }
}

代码示例来源:origin: mulesoft/mule

@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);
 }
}

代码示例来源:origin: org.echocat.jomon/runtime

@Nullable
protected LoggerContextFactory findOriginalFactory() {
  return LogManager.getFactory();
}

代码示例来源:origin: ops4j/org.ops4j.pax.logging

/**
 * 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;
}

代码示例来源:origin: ops4j/org.ops4j.pax.logging

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;
  }
}

代码示例来源:origin: org.mule.modules/mule-module-launcher

public void stop() throws MuleException
{
  coreExtensionManager.stop();
  if (deploymentService != null)
  {
    deploymentService.stop();
  }
  coreExtensionManager.dispose();
  if (LogManager.getFactory() instanceof MuleLog4jContextFactory)
  {
    ((MuleLog4jContextFactory) LogManager.getFactory()).dispose();
  }
}

代码示例来源:origin: org.apache.logging.log4j.adapters/log4j-web

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());
  }
}

代码示例来源:origin: org.apache.druid/druid-server

final LoggerContextFactory contextFactory = LogManager.getFactory();
if (!(contextFactory instanceof Log4jContextFactory)) {
 log.warn(

代码示例来源:origin: ops4j/org.ops4j.pax.logging

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.");

代码示例来源:origin: io.druid/druid-server

final LoggerContextFactory contextFactory = LogManager.getFactory();
if (!(contextFactory instanceof Log4jContextFactory)) {
 log.warn(

代码示例来源:origin: ops4j/org.ops4j.pax.logging

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())) {

代码示例来源:origin: org.mule.runtime/mule-module-launcher

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();
 }
}

代码示例来源:origin: ops4j/org.ops4j.pax.logging

LogManager.getFactory().removeContext(this);
} finally {
  configLock.unlock();

相关文章