ch.qos.logback.classic.Logger.getAppender()方法的使用及代码示例

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

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

Logger.getAppender介绍

暂无

代码示例

代码示例来源:origin: MovingBlocks/Terasology

/**
   * Fetch the logstash appender in the logger context.
   * @return the {@link TelemetryLogstashAppender} in the logger context.
   */
  public static TelemetryLogstashAppender fetchTelemetryLogstashAppender() {
    TelemetryLogstashAppender appender;
    try {
      LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
      appender = (TelemetryLogstashAppender) lc.getLogger(Logger.ROOT_LOGGER_NAME).getAppender("LOGSTASH");
    } catch (Exception e) {
      logger.error("Error when fetching TelemetryLogstashAppender", e);
      return null;
    }
    return appender;
  }
}

代码示例来源:origin: gocd/gocd

FileAppender getGoServerLogFileAppender() {
  return (FileAppender) rootLogger().getAppender("FileAppender");
}

代码示例来源:origin: gocd/gocd

private boolean alreadyInitialized(String pluginId) {
  return ((ch.qos.logback.classic.Logger) LoggerFactory.getLogger(PLUGIN_LOGGER_PREFIX + "." + pluginId)).getAppender(rollingFileAppenderName(pluginId)) != null;
}

代码示例来源:origin: SonarSource/sonarqube

private static void setCustomRootAppender(LoggingConfiguration conf) {
 Logger logger = (Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
 String level = StringUtils.defaultIfBlank(conf.getSubstitutionVariables().get(LoggingConfiguration.PROPERTY_ROOT_LOGGER_LEVEL), LoggingConfiguration.LEVEL_ROOT_DEFAULT);
 if (logger.getAppender(CUSTOM_APPENDER_NAME) == null) {
  logger.detachAndStopAllAppenders();
  logger.addAppender(createAppender(conf.getLogOutput()));
 }
 logger.setLevel(Level.toLevel(level));
}

代码示例来源:origin: bwssytems/ha-bridge

private void setupLoggerSettings() {
//        final ch.qos.logback.classic.Logger logger = lc.getLogger(Logger.ROOT_LOGGER_NAME);

    cyclicBufferAppender = (CyclicBufferAppender<ILoggingEvent>) lc.getLogger(
      Logger.ROOT_LOGGER_NAME).getAppender(CYCLIC_BUFFER_APPENDER_NAME);
    cyclicBufferAppender.setMaxSize(bridgeSettings.getBridgeSettingsDescriptor().getNumberoflogmessages());
//        if(bridgeSettings.getBridgeSettingsDescriptor().getActiveloggers() != null) {
//            for (NameValue temp : bridgeSettings.getBridgeSettingsDescriptor().getActiveloggers()) {
//                if(temp.getValue().equals("false"))
//                    logger.detachAppender(temp.getName());
//            }
//           
//        }
  }

代码示例来源:origin: skylot/jadx

private boolean process(JCommanderWrapper jcw) {
  if (printHelp) {
    jcw.printUsage();
    return false;
  }
  if (printVersion) {
    System.out.println(JadxDecompiler.getVersion());
    return false;
  }
  try {
    if (threadsCount <= 0) {
      throw new JadxException("Threads count must be positive, got: " + threadsCount);
    }
    if (verbose) {
      ch.qos.logback.classic.Logger rootLogger =
          (ch.qos.logback.classic.Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
      // remove INFO ThresholdFilter
      Appender<ILoggingEvent> appender = rootLogger.getAppender("STDOUT");
      if (appender != null) {
        appender.clearAllFilters();
      }
    }
  } catch (JadxException e) {
    System.err.println("ERROR: " + e.getMessage());
    jcw.printUsage();
    return false;
  }
  return true;
}

代码示例来源:origin: ethereum/ethereumj

/**
 * Allow only selected logger to print DEBUG events to STDOUT and FILE.
 * Other loggers are allowed to print ERRORS only.
 */
private static void addSampleLogger(final String loggerName) {
  if (CUSTOM_FILTER == null) {
    CUSTOM_FILTER = new CustomFilter();
    final LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory();
    Appender ca = loggerContext.getLogger("ROOT").getAppender("STDOUT");
    ca.clearAllFilters();
    ca.addFilter(CUSTOM_FILTER);
  }
  CUSTOM_FILTER.addVisibleLogger(loggerName);
}

代码示例来源:origin: SonarSource/sonarqube

@Test
public void do_not_log_to_console() {
 LoggerContext ctx = underTest.configure(props);
 Logger root = ctx.getLogger(Logger.ROOT_LOGGER_NAME);
 Appender appender = root.getAppender("CONSOLE");
 assertThat(appender).isNull();
}

代码示例来源:origin: SonarSource/sonarqube

@Test
public void do_not_log_to_console() {
 LoggerContext ctx = underTest.configure(props);
 Logger root = ctx.getLogger(Logger.ROOT_LOGGER_NAME);
 Appender appender = root.getAppender("CONSOLE");
 assertThat(appender).isNull();
}

代码示例来源:origin: SonarSource/sonarqube

@Test
public void log_to_ce_file() {
 LoggerContext ctx = underTest.configure(props);
 Logger root = ctx.getLogger(Logger.ROOT_LOGGER_NAME);
 Appender<ILoggingEvent> appender = root.getAppender("file_ce");
 assertThat(appender).isInstanceOf(FileAppender.class);
 FileAppender fileAppender = (FileAppender) appender;
 assertThat(fileAppender.getFile()).isEqualTo(new File(logDir, "ce.log").getAbsolutePath());
 assertThat(fileAppender.getEncoder()).isInstanceOf(PatternLayoutEncoder.class);
 PatternLayoutEncoder encoder = (PatternLayoutEncoder) fileAppender.getEncoder();
 assertThat(encoder.getPattern()).isEqualTo("%d{yyyy.MM.dd HH:mm:ss} %-5level ce[%X{ceTaskUuid}][%logger{20}] %msg%n");
}

代码示例来源:origin: SonarSource/sonarqube

@Test
public void log_to_web_file() {
 LoggerContext ctx = underTest.configure(props);
 Logger root = ctx.getLogger(Logger.ROOT_LOGGER_NAME);
 Appender<ILoggingEvent> appender = root.getAppender("file_web");
 assertThat(appender).isInstanceOf(FileAppender.class);
 FileAppender fileAppender = (FileAppender) appender;
 assertThat(fileAppender.getFile()).isEqualTo(new File(logDir, "web.log").getAbsolutePath());
 assertThat(fileAppender.getEncoder()).isInstanceOf(PatternLayoutEncoder.class);
 PatternLayoutEncoder encoder = (PatternLayoutEncoder) fileAppender.getEncoder();
 assertThat(encoder.getPattern()).isEqualTo("%d{yyyy.MM.dd HH:mm:ss} %-5level web[%X{HTTP_REQUEST_ID}][%logger{20}] %msg%n");
}

代码示例来源:origin: SonarSource/sonarqube

private void verifyGobblerConsoleAppender(Logger logger) {
 Appender<ILoggingEvent> appender = logger.getAppender("GOBBLER_CONSOLE");
 assertThat(appender).isInstanceOf(ConsoleAppender.class);
 ConsoleAppender<ILoggingEvent> consoleAppender = (ConsoleAppender<ILoggingEvent>) appender;
 assertThat(consoleAppender.getTarget()).isEqualTo(ConsoleTarget.SystemOut.getName());
 verifyFormattedLogEncoder(consoleAppender.getEncoder(), "%msg%n");
}

代码示例来源:origin: SonarSource/sonarqube

@Test
public void root_logger_writes_to_console_with_formatting_and_to_sonar_log_file_when_running_from_ITs() {
 emulateRunFromCommandLine(true);
 LoggerContext ctx = underTest.configure();
 Logger rootLogger = ctx.getLogger(ROOT_LOGGER_NAME);
 verifyAppConsoleAppender(rootLogger.getAppender("APP_CONSOLE"));
 verifySonarLogFileAppender(rootLogger.getAppender("file_sonar"));
 assertThat(rootLogger.iteratorForAppenders()).hasSize(2);
 ctx.getLoggerList()
  .stream()
  .filter(logger -> !ROOT_LOGGER_NAME.equals(logger.getName()))
  .forEach(AppLoggingTest::verifyNoFileAppender);
}

代码示例来源:origin: SonarSource/sonarqube

@Test
public void startup_logger_prints_to_only_to_system_out() {
 LoggerContext ctx = underTest.configure(props);
 Logger startup = ctx.getLogger("startup");
 assertThat(startup.isAdditive()).isFalse();
 Appender appender = startup.getAppender("CONSOLE");
 assertThat(appender).isInstanceOf(ConsoleAppender.class);
 ConsoleAppender<ILoggingEvent> consoleAppender = (ConsoleAppender<ILoggingEvent>) appender;
 assertThat(consoleAppender.getTarget()).isEqualTo("System.out");
 assertThat(consoleAppender.getEncoder()).isInstanceOf(PatternLayoutEncoder.class);
 PatternLayoutEncoder patternEncoder = (PatternLayoutEncoder) consoleAppender.getEncoder();
 assertThat(patternEncoder.getPattern()).isEqualTo("%d{yyyy.MM.dd HH:mm:ss} %-5level app[][%logger{20}] %msg%n");
}

代码示例来源:origin: SonarSource/sonarqube

@Test
public void startup_logger_prints_to_only_to_system_out() {
 LoggerContext ctx = underTest.configure(props);
 Logger startup = ctx.getLogger("startup");
 assertThat(startup.isAdditive()).isFalse();
 Appender appender = startup.getAppender("CONSOLE");
 assertThat(appender).isInstanceOf(ConsoleAppender.class);
 ConsoleAppender<ILoggingEvent> consoleAppender = (ConsoleAppender<ILoggingEvent>) appender;
 assertThat(consoleAppender.getTarget()).isEqualTo("System.out");
 assertThat(consoleAppender.getEncoder()).isInstanceOf(PatternLayoutEncoder.class);
 PatternLayoutEncoder patternEncoder = (PatternLayoutEncoder) consoleAppender.getEncoder();
 assertThat(patternEncoder.getPattern()).isEqualTo("%d{yyyy.MM.dd HH:mm:ss} %-5level app[][%logger{20}] %msg%n");
}

代码示例来源:origin: SonarSource/sonarqube

@Test
public void root_logger_writes_to_console_with_formatting_and_to_sonar_log_file_when_running_from_command_line() {
 emulateRunFromCommandLine(false);
 LoggerContext ctx = underTest.configure();
 Logger rootLogger = ctx.getLogger(ROOT_LOGGER_NAME);
 verifyAppConsoleAppender(rootLogger.getAppender("APP_CONSOLE"));
 verifySonarLogFileAppender(rootLogger.getAppender("file_sonar"));
 assertThat(rootLogger.iteratorForAppenders()).hasSize(2);
 // verify no other logger writes to sonar.log
 ctx.getLoggerList()
  .stream()
  .filter(logger -> !ROOT_LOGGER_NAME.equals(logger.getName()))
  .forEach(AppLoggingTest::verifyNoFileAppender);
}

代码示例来源:origin: kairosdb/kairosdb

Appender<ILoggingEvent> stdout = root.getAppender("stdout");
if (stdout != null)

代码示例来源:origin: SonarSource/sonarqube

@Test
public void configure_no_rotation_on_sonar_file() {
 settings.getProps().set("sonar.log.rollingPolicy", "none");
 LoggerContext ctx = underTest.configure();
 Logger rootLogger = ctx.getLogger(ROOT_LOGGER_NAME);
 Appender<ILoggingEvent> appender = rootLogger.getAppender("file_sonar");
 assertThat(appender)
  .isNotInstanceOf(RollingFileAppender.class)
  .isInstanceOf(FileAppender.class);
}

代码示例来源:origin: SonarSource/sonarqube

@Test
public void root_logger_only_writes_to_console_with_formatting_when_running_from_sonar_script() {
 emulateRunFromSonarScript();
 LoggerContext ctx = underTest.configure();
 Logger rootLogger = ctx.getLogger(ROOT_LOGGER_NAME);
 ConsoleAppender<ILoggingEvent> consoleAppender = (ConsoleAppender<ILoggingEvent>) rootLogger.getAppender("APP_CONSOLE");
 verifyAppFormattedLogEncoder(consoleAppender.getEncoder());
 assertThat(rootLogger.iteratorForAppenders()).hasSize(1);
}

代码示例来源:origin: line/armeria

@Test
public void testXmlConfig() throws Exception {
  try {
    final JoranConfigurator configurator = new JoranConfigurator();
    configurator.setContext(context);
    context.reset();
    configurator.doConfigure(getClass().getResource("testXmlConfig.xml"));
    final RequestContextExportingAppender rcea =
        (RequestContextExportingAppender) logger.getAppender("RCEA");
    assertThat(rcea).isNotNull();
    assertThat(rcea.getBuiltIns()).containsExactly(BuiltInProperty.REMOTE_HOST);
    assertThat(rcea.getHttpRequestHeaders()).containsExactly(HttpHeaderNames.USER_AGENT);
    assertThat(rcea.getHttpResponseHeaders()).containsExactly(HttpHeaderNames.SET_COOKIE);
    final AttributeKey<Object> fooAttr = AttributeKey.valueOf("com.example.AttrKeys#FOO");
    final AttributeKey<Object> barAttr = AttributeKey.valueOf("com.example.AttrKeys#BAR");
    assertThat(rcea.getAttributes()).containsOnly(new SimpleEntry<>("foo", fooAttr),
                           new SimpleEntry<>("bar", barAttr));
  } finally {
    // Revert to the original configuration.
    final JoranConfigurator configurator = new JoranConfigurator();
    configurator.setContext(context);
    context.reset();
    configurator.doConfigure(getClass().getResource("/logback-test.xml"));
  }
}

相关文章