org.apache.logging.log4j.core.config.Configuration.addListener()方法的使用及代码示例

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

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

Configuration.addListener介绍

暂无

代码示例

代码示例来源:origin: org.apereo.cas/cas-server-core-logging

@SneakyThrows
  private static Optional<Pair<Resource, LoggerContext>> buildLoggerContext(final Environment environment, final ResourceLoader
    resourceLoader) {
    val logFile = environment.getProperty("logging.config", "classpath:/log4j2.xml");
    LOGGER.info("Located logging configuration reference in the environment as [{}]", logFile);

    if (ResourceUtils.doesResourceExist(logFile, resourceLoader)) {
      val logConfigurationFile = resourceLoader.getResource(logFile);
      LOGGER.trace("Loaded logging configuration resource [{}]. Initializing logger context...", logConfigurationFile);
      val loggerContext = Configurator.initialize("CAS", null, logConfigurationFile.getURI());
      LOGGER.trace("Installing log configuration listener to detect changes and update");
      loggerContext.getConfiguration().addListener(reconfigurable -> loggerContext.updateLoggers(reconfigurable.reconfigure()));
      return Optional.of(Pair.of(logConfigurationFile, loggerContext));
    }
    LOGGER.warn("Logging configuration cannot be found in the environment settings");
    return Optional.empty();
  }
}

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

try {
  final Configuration prev = this.configuration;
  config.addListener(this);

代码示例来源:origin: Netflix/spectator

/**
 * Add the spectator appender to the root logger. This method is intended to be called once
 * as part of the applications initialization process.
 *
 * @param registry
 *     Spectator registry to use for the appender.
 * @param name
 *     Name for the appender.
 * @param ignoreExceptions
 *     If set to true then the stack trace metrics are disabled.
 */
public static void addToRootLogger(
  Registry registry,
  String name,
  boolean ignoreExceptions) {
 final Appender appender = new SpectatorAppender(registry, name, null, null, ignoreExceptions);
 appender.start();
 LoggerContext context = (LoggerContext) LogManager.getContext(false);
 Configuration config = context.getConfiguration();
 addToRootLogger(appender);
 config.addListener(reconfigurable -> addToRootLogger(appender));
}

相关文章