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

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

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

LogManager.setRepositorySelector介绍

[英]Sets LoggerFactory but only if the correct guard is passed as parameter.

Initally the guard is null. If the guard is null, then invoking this method sets the logger factory and the guard. Following invocations will throw a IllegalArgumentException, unless the previously set guard is passed as the second parameter.

This allows a high-level component to set the RepositorySelector used by the LogManager.

For example, when tomcat starts it will be able to install its own repository selector. However, if and when Tomcat is embedded within JBoss, then JBoss will install its own repository selector and Tomcat will use the repository selector set by its container, JBoss.
[中]设置LoggerFactory,但仅当正确的guard作为参数传递时。
最初,保护是空的。如果防护为null,则调用此方法将设置记录器工厂和防护。以下调用将抛出IllegalArgumentException,除非之前的集合guard作为第二个参数传递。
这允许高级组件设置LogManager使用的RepositorySelector。
例如,当tomcat启动时,它将能够安装自己的存储库选择器。但是,如果Tomcat嵌入到JBoss中,JBoss将安装自己的存储库选择器,Tomcat将使用其容器JBoss设置的存储库选择器。

代码示例

代码示例来源:origin: org.jboss.logmanager/jboss-logmanager-log4j

/**
   * Container install method.  Performs two steps: installs this repository selector into the log4j logmanager, and
   * clears the system property which prevents log4j from initializing (thus allowing other log4j instances to be
   * started and configured independently).
   */
  public void start() {
    LogManager.setRepositorySelector(this, guard);
    AccessController.doPrivileged(new PrivilegedAction<Void>() {
      public Void run() {
        try {
          System.clearProperty("log4j.defaultInitOverride");
        } catch (SecurityException ex) {
          log.log(Level.WARN, "Unable to clear system property 'log4j.defaultInitOverride': " +
              ex.getMessage() + " (nested log4j deployments may not function as expected");
        }
        return null;
      }
    });
  }
}

代码示例来源:origin: org.apache.apex/apex-engine

@VisibleForTesting
static void initializeLogger()
{
 LogManager.setRepositorySelector(new DefaultRepositorySelector(new DelegatingLoggerRepository(LogManager.getLoggerRepository())), null);
}

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

@Override
public void close() throws Exception {
  synchronized (this) {
      try {
        try {
          closeQuietly(_installation);
        } finally {
          _installation = null;
        }
      } finally {
        try {
          try {
            if (_selector != null) {
              setRepositorySelector(_originalSelector, null);
            }
          } finally {
            try {
              closeQuietly(_loggerFactoryRegistration);
            } finally {
              _loggerFactoryRegistration = null;
            }
          }
        } finally {
          _loggerFactory = null;
          _selector = null;
        }
    }
  }
}

代码示例来源:origin: net.dataforte/dataforte-commons

/**
 * Register with this repository selector.
 */
public static synchronized void init() {
  if (!initialized) // set the global RepositorySelector
  {
    defaultRepository = LogManager.getLoggerRepository();
    RepositorySelector theSelector = new ContextRepositorySelector();
    LogManager.setRepositorySelector(theSelector, guard);
    initialized = true;
  }
  Hierarchy hierarchy = new Hierarchy(new RootLogger(Level.DEBUG));
  ClassLoader loader = Thread.currentThread().getContextClassLoader();
  try {
    loadLog4JConfig(hierarchy, loader);
  } catch (Exception e) {
    throw new RuntimeException("Could not initialize ContextRepositorySelector", e);
  }
  
  repositories.put(loader, hierarchy);        
}

代码示例来源:origin: com.netflix.blitz4j/blitz4j

org.apache.log4j.LogManager.setRepositorySelector(new NFRepositorySelector(nfHierarchy), guard);

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

public void init(@Nonnull Log4JBasedLoggingEnvironmentConfiguration with) {
  synchronized (this) {
    if (_selector == null) {
      _originalSelector = findOriginalSelector();
      _selector = createSelectorFor(with);
      _loggerFactory = new LoggerFactory(_selector.getLoggerRepository());
      setRepositorySelector(_selector, null);
      _loggerFactoryRegistration = LoggerFactoryRegistry.register(_loggerFactory);
      if (with.isInstallSl4jRequired()) {
        _installation = Slf4jUtils.tryInstallSlf4jBridges(_loggerFactory);
      }
    }
  }
}

相关文章