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

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

本文整理了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

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

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

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

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

  1. if (result == null && ProviderUtil.hasProviders() && LogManager.getFactory() != null) { //LOG4J2-1658
  2. final String factoryClassName = LogManager.getFactory().getClass().getName();
  3. for (final Provider provider : ProviderUtil.getProviders()) {
  4. if (factoryClassName.equals(provider.getClassName())) {

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

  1. @Test
  2. public void testShutdownCallbackRegistry() throws Exception {
  3. final LoggerContext context = ctx.getLoggerContext();
  4. assertTrue("LoggerContext should be started", context.isStarted());
  5. assertThat(Registry.CALLBACKS, hasSize(1));
  6. Registry.shutdown();
  7. assertTrue("LoggerContext should be stopped", context.isStopped());
  8. assertThat(Registry.CALLBACKS, hasSize(0));
  9. final ContextSelector selector = ((Log4jContextFactory) LogManager.getFactory()).getSelector();
  10. assertThat(selector.getLoggerContexts(), not(hasItem(context)));
  11. }

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

  1. @Test
  2. public void testAsyncLoggingInitialization() throws Exception {
  3. HiveConf conf = new HiveConf();
  4. conf.setBoolVar(ConfVars.HIVE_ASYNC_LOG_ENABLED, false);
  5. LogUtils.initHiveLog4jCommon(conf, ConfVars.HIVE_LOG4J_FILE);
  6. Log4jContextFactory log4jContextFactory = (Log4jContextFactory) LogManager.getFactory();
  7. ContextSelector contextSelector = log4jContextFactory.getSelector();
  8. assertTrue(contextSelector instanceof ClassLoaderContextSelector);
  9. conf.setBoolVar(ConfVars.HIVE_ASYNC_LOG_ENABLED, true);
  10. LogUtils.initHiveLog4jCommon(conf, ConfVars.HIVE_LOG4J_FILE);
  11. log4jContextFactory = (Log4jContextFactory) LogManager.getFactory();
  12. contextSelector = log4jContextFactory.getSelector();
  13. assertTrue(contextSelector instanceof AsyncLoggerContextSelector);
  14. }
  15. }

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

  1. private void initializeJndi(final String location) {
  2. final URI configLocation = getConfigURI(location);
  3. if (this.name == null) {
  4. throw new IllegalStateException("A log4jContextName context parameter is required");
  5. }
  6. LoggerContext context;
  7. final LoggerContextFactory factory = LogManager.getFactory();
  8. if (factory instanceof Log4jContextFactory) {
  9. final ContextSelector selector = ((Log4jContextFactory) factory).getSelector();
  10. if (selector instanceof NamedContextSelector) {
  11. this.namedContextSelector = (NamedContextSelector) selector;
  12. context = this.namedContextSelector.locateContext(this.name, this.servletContext, configLocation);
  13. ContextAnchor.THREAD_CONTEXT.set(context);
  14. if (context.isInitialized()) {
  15. context.start();
  16. }
  17. ContextAnchor.THREAD_CONTEXT.remove();
  18. } else {
  19. LOGGER.warn("Potential problem: Selector is not an instance of NamedContextSelector.");
  20. return;
  21. }
  22. } else {
  23. LOGGER.warn("Potential problem: LoggerContextFactory is not an instance of Log4jContextFactory.");
  24. return;
  25. }
  26. this.loggerContext = context;
  27. LOGGER.debug("Created logger context for [{}] using [{}].", this.name, context.getClass().getClassLoader());
  28. }

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

  1. public void stop() throws MuleException {
  2. MuleContainerBootstrap.dispose();
  3. if (deploymentService != null) {
  4. deploymentService.stop();
  5. }
  6. if (extensionModelLoaderManager != null) {
  7. extensionModelLoaderManager.stop();
  8. }
  9. coreExtensionManager.stop();
  10. coreExtensionManager.dispose();
  11. if (serviceManager != null) {
  12. serviceManager.stop();
  13. }
  14. if (toolingService != null) {
  15. toolingService.stop();
  16. }
  17. if (LogManager.getFactory() instanceof MuleLog4jContextFactory) {
  18. ((MuleLog4jContextFactory) LogManager.getFactory()).dispose();
  19. }
  20. if (log4jContextFactory != null) {
  21. log4jContextFactory.dispose();
  22. }
  23. }

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

  1. @Test
  2. public void disposesLogContextFactory() throws Exception {
  3. final LoggerContextFactory originalFactory = LogManager.getFactory();
  4. try {
  5. MuleLog4jContextFactory contextFactory = mock(MuleLog4jContextFactory.class);
  6. LogManager.setFactory(contextFactory);
  7. container.stop();
  8. verify(contextFactory).dispose();
  9. } finally {
  10. LogManager.setFactory(originalFactory);
  11. }
  12. }

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

  1. @Nullable
  2. protected LoggerContextFactory findOriginalFactory() {
  3. return LogManager.getFactory();
  4. }

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

  1. /**
  2. * Returns the {@code ContextSelector} of the current {@code Log4jContextFactory}.
  3. *
  4. * @return the {@code ContextSelector} of the current {@code Log4jContextFactory}
  5. */
  6. private static ContextSelector getContextSelector() {
  7. final LoggerContextFactory factory = LogManager.getFactory();
  8. if (factory instanceof Log4jContextFactory) {
  9. final ContextSelector selector = ((Log4jContextFactory) factory).getSelector();
  10. return selector;
  11. }
  12. return null;
  13. }

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

  1. private static Log4jContextFactory getFactory() {
  2. final LoggerContextFactory factory = LogManager.getFactory();
  3. if (factory instanceof Log4jContextFactory) {
  4. return (Log4jContextFactory) factory;
  5. } else if (factory != null) {
  6. LOGGER.error("LogManager returned an instance of {} which does not implement {}. Unable to initialize Log4j.",
  7. factory.getClass().getName(), Log4jContextFactory.class.getName());
  8. return null;
  9. } else {
  10. LOGGER.fatal("LogManager did not return a LoggerContextFactory. This indicates something has gone terribly wrong!");
  11. return null;
  12. }
  13. }

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

  1. public void stop() throws MuleException
  2. {
  3. coreExtensionManager.stop();
  4. if (deploymentService != null)
  5. {
  6. deploymentService.stop();
  7. }
  8. coreExtensionManager.dispose();
  9. if (LogManager.getFactory() instanceof MuleLog4jContextFactory)
  10. {
  11. ((MuleLog4jContextFactory) LogManager.getFactory()).dispose();
  12. }
  13. }

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

  1. public void init(final FilterConfig filterConfig) throws ServletException {
  2. context = filterConfig.getServletContext();
  3. name = filterConfig.getInitParameter(CONTEXT_NAME);
  4. final String configLocn = filterConfig.getInitParameter(CONFIG_LOCATION);
  5. if (name == null) {
  6. throw new UnavailableException("A context-name attribute is required");
  7. }
  8. if (context.getAttribute(Log4jContextListener.LOG4J_CONTEXT_ATTRIBUTE) == null) {
  9. LoggerContext ctx;
  10. final LoggerContextFactory factory = LogManager.getFactory();
  11. if (factory instanceof Log4jContextFactory) {
  12. final ContextSelector sel = ((Log4jContextFactory) factory).getSelector();
  13. if (sel instanceof NamedContextSelector) {
  14. selector = (NamedContextSelector) sel;
  15. ctx = selector.locateContext(name, configLocn);
  16. } else {
  17. return;
  18. }
  19. } else {
  20. return;
  21. }
  22. context.setAttribute(Log4jContextListener.LOG4J_CONTEXT_ATTRIBUTE, ctx);
  23. created = true;
  24. context.log("Created context for " + name + " using " + ctx.getClass().getClassLoader());
  25. }
  26. }

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

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

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

  1. private void setUpShutdownHook() {
  2. if (shutdownCallback == null) {
  3. final LoggerContextFactory factory = LogManager.getFactory();
  4. if (factory instanceof ShutdownCallbackRegistry) {
  5. LOGGER.debug(SHUTDOWN_HOOK_MARKER, "Shutdown hook enabled. Registering a new one.");

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

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

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

  1. if (result == null && ProviderUtil.hasProviders() && LogManager.getFactory() != null) { //LOG4J2-1658
  2. final String factoryClassName = LogManager.getFactory().getClass().getName();
  3. for (final Provider provider : ProviderUtil.getProviders()) {
  4. if (factoryClassName.equals(provider.getClassName())) {

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

  1. public void stop() throws MuleException {
  2. MuleContainerBootstrap.dispose();
  3. if (deploymentService != null) {
  4. deploymentService.stop();
  5. }
  6. if (extensionModelLoaderManager != null) {
  7. extensionModelLoaderManager.stop();
  8. }
  9. coreExtensionManager.stop();
  10. coreExtensionManager.dispose();
  11. if (serviceManager != null) {
  12. serviceManager.stop();
  13. }
  14. if (toolingService != null) {
  15. toolingService.stop();
  16. }
  17. if (LogManager.getFactory() instanceof MuleLog4jContextFactory) {
  18. ((MuleLog4jContextFactory) LogManager.getFactory()).dispose();
  19. }
  20. if (log4jContextFactory != null) {
  21. log4jContextFactory.dispose();
  22. }
  23. }

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

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

相关文章