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

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

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

Configuration.getLoggers介绍

暂无

代码示例

代码示例来源:origin: Graylog2/graylog2-server

@VisibleForTesting
protected Collection<LoggerConfig> getLoggerConfigs() {
  final LoggerContext loggerContext = (LoggerContext) LogManager.getContext(false);
  final Configuration configuration = loggerContext.getConfiguration();
  return configuration.getLoggers().values();
}

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

public Map<String, Level> getLoggerLevels() {
  Configuration loggerConfig = ((LoggerContext) LogManager.getContext(false)).getConfiguration();
  Map<String, Level> logLevelMap = new HashMap<>();
  for (Map.Entry<String, LoggerConfig> entry : loggerConfig.getLoggers().entrySet()) {
    logLevelMap.put(entry.getKey(), entry.getValue().getLevel());
  }
  return logLevelMap;
}

代码示例来源:origin: org.springframework.boot/spring-boot

private LoggerConfig getLoggerConfig(String name) {
  if (!StringUtils.hasLength(name) || ROOT_LOGGER_NAME.equals(name)) {
    name = LogManager.ROOT_LOGGER_NAME;
  }
  return getLoggerContext().getConfiguration().getLoggers().get(name);
}

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

private boolean hasDebugOrLower(final Configuration config) {
 for (LoggerConfig loggerConfig : config.getLoggers().values()) {
  boolean isDebugOrLower = loggerConfig.getLevel().isLessSpecificThan(Level.DEBUG);
  if (isDebugOrLower) {
   return true;
  }
 }
 return false;
}

代码示例来源:origin: org.springframework.boot/spring-boot

@Override
public List<LoggerConfiguration> getLoggerConfigurations() {
  List<LoggerConfiguration> result = new ArrayList<>();
  Configuration configuration = getLoggerContext().getConfiguration();
  for (LoggerConfig loggerConfig : configuration.getLoggers().values()) {
    result.add(convertLoggerConfiguration(loggerConfig));
  }
  result.sort(CONFIGURATION_COMPARATOR);
  return result;
}

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

private boolean hasLoggerFilter(final Configuration config) {
 for (LoggerConfig loggerConfig : config.getLoggers().values()) {
  boolean isRoot = loggerConfig.getName().equals("");
  boolean isGemFire = loggerConfig.getName().startsWith(GEODE_LOGGER_PREFIX);
  boolean hasFilter = loggerConfig.hasFilter();
  boolean isGemFireVerboseFilter =
    hasFilter && (GEODE_VERBOSE_FILTER.equals(loggerConfig.getFilter().toString())
      || GEMFIRE_VERBOSE_FILTER.equals(loggerConfig.getFilter().toString()));
  if (isRoot || isGemFire) {
   // check for Logger Filter
   if (hasFilter && !isGemFireVerboseFilter) {
    return true;
   }
  }
 }
 return false;
}

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

private boolean hasAppenderRefFilter(final Configuration config) {
  for (LoggerConfig loggerConfig : config.getLoggers().values()) {
   boolean isRoot = loggerConfig.getName().equals("");
   boolean isGemFire = loggerConfig.getName().startsWith(GEODE_LOGGER_PREFIX);

   if (isRoot || isGemFire) {
    // check for AppenderRef Filter
    for (AppenderRef appenderRef : loggerConfig.getAppenderRefs()) {
     if (appenderRef.getFilter() != null) {
      return true;
     }
    }
   }
  }
  return false;
 }
}

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

private void listLoggers(final HttpServletResponse response) throws IOException {
  PrintWriter writer = null;
  try {
   writer = response.getWriter();
   ConfLoggers confLoggers = new ConfLoggers();
   Collection<LoggerConfig> loggerConfigs = conf.getLoggers().values();
   loggerConfigs.forEach(lc -> confLoggers.getLoggers().add(new ConfLogger(lc.getName(), lc.getLevel().toString())));
   ObjectMapper objectMapper = new ObjectMapper();
   objectMapper.writerWithDefaultPrettyPrinter().writeValue(writer, confLoggers);
  } catch (IOException e) {
   LOG.error("Caught an exception while processing Log4j2 configuration request", e);
   response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
   return;
  } finally {
   if (writer != null) {
    writer.close();
   }
  }
  response.setStatus(HttpServletResponse.SC_OK);
 }
}

代码示例来源:origin: igniterealtime/Openfire

void removeAppender(final String name) {
  final LoggerContext context = LoggerContext.getContext(false);
  final Configuration config = context.getConfiguration();
  config.getAppenders().remove( name ).stop();
  for (final LoggerConfig loggerConfig : config.getLoggers().values()) {
    loggerConfig.removeAppender( name );
  }
  config.getRootLogger().removeAppender( name );
}

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

private void updateLogLevel(final LogConfig logConfig,
  final LogLevelUpdateScope logLevelUpdateScope) {
 Level level = toLevel(LogWriterLevel.find(logConfig.getLogLevel()));
 Configuration configuration =
   getRootLoggerContext().getConfiguration();
 Collection<LoggerConfig> loggerConfigs = new HashSet<>();
 for (LoggerConfig loggerConfig : configuration.getLoggers().values()) {
  switch (logLevelUpdateScope) {
   case ALL_LOGGERS:
    loggerConfigs.add(loggerConfig);
    break;
   case GEODE_AND_SECURITY_LOGGERS:
    if (loggerConfig.getName().startsWith(GEODE_LOGGER_PREFIX)) {
     loggerConfigs.add(loggerConfig);
    }
    break;
   case GEODE_AND_APPLICATION_LOGGERS:
    if (!loggerConfig.getName().equals(SECURITY_LOGGER_NAME)) {
     loggerConfigs.add(loggerConfig);
    }
    break;
   case GEODE_LOGGERS:
    if (loggerConfig.getName().startsWith(GEODE_LOGGER_PREFIX) &&
      !loggerConfig.getName().equals(SECURITY_LOGGER_NAME)) {
     loggerConfigs.add(loggerConfig);
    }
  }
 }
 updateLogLevel(level, loggerConfigs.toArray(new LoggerConfig[0]));
}

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

static void updateLoggers(final Appender appender, final Configuration config) {
  final Level level = null;
  final Filter filter = null;
  for (final LoggerConfig loggerConfig : config.getLoggers().values()) {
    loggerConfig.addAppender(appender, level, filter);
  }
  config.getRootLogger().addAppender(appender, level, filter);
}

代码示例来源:origin: igniterealtime/Openfire

String addAppender(final Writer writer) {
  final String name = "openfire-s2s-test-appender-" + StringUtils.randomString( 10 );
  final LoggerContext context = LoggerContext.getContext(false);
  final Configuration config = context.getConfiguration();
  final PatternLayout layout = PatternLayout.createDefaultLayout(config);
  final Appender appender = WriterAppender.createAppender(layout, null, writer, name, false, true);
  appender.start();
  config.addAppender(appender);
  final Level level = null;
  final Filter filter = null;
  for (final LoggerConfig loggerConfig : config.getLoggers().values()) {
    loggerConfig.addAppender(appender, level, filter);
  }
  config.getRootLogger().addAppender(appender, level, filter);
  return name;
}

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

@Test
  public void testPropertiesConfiguration() {
    final Configuration config = context.getConfiguration();
    assertNotNull("No configuration created", config);
    assertEquals("Incorrect State: " + config.getState(), config.getState(), LifeCycle.State.STARTED);
    final Map<String, Appender> appenders = config.getAppenders();
    assertNotNull(appenders);
    assertTrue("Incorrect number of Appenders: " + appenders.size(), appenders.size() == 1);
    final Map<String, LoggerConfig> loggers = config.getLoggers();
    assertNotNull(loggers);
    assertTrue("Incorrect number of LoggerConfigs: " + loggers.size(), loggers.size() == 1);
    final Filter filter = config.getFilter();
    assertNotNull("No Filter", filter);
    assertTrue("Not a Threshold Filter", filter instanceof ThresholdFilter);
    final Logger logger = LogManager.getLogger(getClass());
    logger.info("Welcome to Log4j!");
  }
}

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

@Test
  public void testPropertiesConfiguration() {
    final Configuration config = context.getConfiguration();
    assertNotNull("No configuration created", config);
    assertEquals("Incorrect State: " + config.getState(), config.getState(), LifeCycle.State.STARTED);
    final Map<String, Appender> appenders = config.getAppenders();
    assertNotNull(appenders);
    assertTrue("Incorrect number of Appenders: " + appenders.size(), appenders.size() == 1);
    final Map<String, LoggerConfig> loggers = config.getLoggers();
    assertNotNull(loggers);
    assertTrue("Incorrect number of LoggerConfigs: " + loggers.size(), loggers.size() == 2);
    final Filter filter = config.getFilter();
    assertNotNull("No Filter", filter);
    assertTrue("Not a Threshold Filter", filter instanceof ThresholdFilter);
    final Logger logger = LogManager.getLogger(getClass());
    logger.info("Welcome to Log4j!");
  }
}

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

@Test
  public void testPropertiesConfiguration() {
    final Configuration config = context.getConfiguration();
    assertNotNull("No configuration created", config);
    assertEquals("Incorrect State: " + config.getState(), config.getState(), LifeCycle.State.STARTED);
    final Map<String, Appender> appenders = config.getAppenders();
    assertNotNull(appenders);
    assertTrue("Incorrect number of Appenders: " + appenders.size(), appenders.size() == 3);
    final Map<String, LoggerConfig> loggers = config.getLoggers();
    assertNotNull(loggers);
    assertTrue("Incorrect number of LoggerConfigs: " + loggers.size(), loggers.size() == 2);
    final Filter filter = config.getFilter();
    assertNotNull("No Filter", filter);
    assertTrue("Not a Threshold Filter", filter instanceof ThresholdFilter);
    final Logger logger = LogManager.getLogger(getClass());
    logger.info("Welcome to Log4j!");
  }
}

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

@Test
  public void testPropertiesConfiguration() {
    final Configuration config = context.getConfiguration();
    assertNotNull("No configuration created", config);
    assertEquals("Incorrect State: " + config.getState(), config.getState(), LifeCycle.State.STARTED);
    final Map<String, Appender> appenders = config.getAppenders();
    assertNotNull(appenders);
    assertTrue("Incorrect number of Appenders: " + appenders.size(), appenders.size() == 1);
    final Map<String, LoggerConfig> loggers = config.getLoggers();
    assertNotNull(loggers);
    assertTrue("Incorrect number of LoggerConfigs: " + loggers.size(), loggers.size() == 2);
    final Filter filter = config.getFilter();
    assertNotNull("No Filter", filter);
    assertTrue("Not a Threshold Filter", filter instanceof ThresholdFilter);
    final Logger logger = LogManager.getLogger(getClass());

    assertEquals("Incorrect level " + logger.getLevel(), Level.DEBUG, logger.getLevel());

    logger.debug("Welcome to Log4j!");
  }
}

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

final KafkaAppender kafkaAppender = (KafkaAppender)appenders.get("Kafka");
final GelfLayout gelfLayout = (GelfLayout)kafkaAppender.getLayout();
final Map<String, LoggerConfig> loggers = config.getLoggers();
assertNotNull(loggers);
assertTrue("Incorrect number of LoggerConfigs: " + loggers.size(), loggers.size() == 2);

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

assertThat(map, hasKey("DefaultConsole-2"));
final Map<String, LoggerConfig> loggerMap = config.getLoggers();
assertNotNull("loggerMap not null", loggerMap);
assertThat("There should only be one configured logger", loggerMap, hasSize(1));

代码示例来源:origin: org.elasticsearch/elasticsearch

public static void setLevel(Logger logger, Level level) {
  if (!LogManager.ROOT_LOGGER_NAME.equals(logger.getName())) {
    Configurator.setLevel(logger.getName(), level);
  } else {
    final LoggerContext ctx = LoggerContext.getContext(false);
    final Configuration config = ctx.getConfiguration();
    final LoggerConfig loggerConfig = config.getLoggerConfig(logger.getName());
    loggerConfig.setLevel(level);
    ctx.updateLoggers();
  }
  // we have to descend the hierarchy
  final LoggerContext ctx = LoggerContext.getContext(false);
  for (final LoggerConfig loggerConfig : ctx.getConfiguration().getLoggers().values()) {
    if (LogManager.ROOT_LOGGER_NAME.equals(logger.getName()) || loggerConfig.getName().startsWith(logger.getName() + ".")) {
      Configurator.setLevel(loggerConfig.getName(), level);
    }
  }
}

代码示例来源:origin: org.apache.geode/gemfire-core

public static boolean hasDebugOrLower(final Configuration config) {
 for (LoggerConfig loggerConfig : config.getLoggers().values()) {
  boolean isDebugOrLower = loggerConfig.getLevel().isLessSpecificThan(Level.DEBUG);
  if (isDebugOrLower) {
   return true;
  }
 }
 return false;
}

相关文章