ch.qos.logback.core.Appender类的使用及代码示例

x33g5p2x  于2022-01-15 转载在 其他  
字(8.7k)|赞(0)|评价(0)|浏览(252)

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

Appender介绍

暂无

代码示例

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

@Test
public void shouldLogErrorWhenRegisterCommandWithoutSenderAnnotation() {
  //see https://github.com/MovingBlocks/Terasology/issues/2679
  Appender<ILoggingEvent> appender = mockAppender();
  ((ch.qos.logback.classic.Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME)).addAppender(appender);
  systemUnderTest.register(new SystemWithCommandMissingSenderAnnotation());
  systemUnderTest.initialise();
  ArgumentCaptor<LoggingEvent> loggingEventArgumentCaptor = ArgumentCaptor.forClass(LoggingEvent.class);
  verify(appender).doAppend(loggingEventArgumentCaptor.capture());
  List<String> allErrorLogMessages = loggingEventArgumentCaptor.getAllValues().stream()
      .filter(e -> e.getLevel().isGreaterOrEqual(Level.ERROR))
      .map(LoggingEvent::getFormattedMessage)
      .collect(toList());
  String expectedMessage = "Command commandWithoutSenderAnnotation provided by " +
      "SystemWithCommandMissingSenderAnnotation contains a EntityRef without @Sender annotation, " +
      "may cause a NullPointerException";
  assertThat(allErrorLogMessages, hasItem(expectedMessage));
}

代码示例来源:origin: alibaba/nacos

private static List<AppenderInfo> doGetLoggerAppenders(Iterator<Appender<ILoggingEvent>> appenders) {
    List<AppenderInfo> result = new ArrayList<AppenderInfo>();

    while (appenders.hasNext()) {
      AppenderInfo info = new AppenderInfo();
      Appender<ILoggingEvent> appender = appenders.next();
      info.setName(appender.getName());
      info.setType(appender.getClass().getName());
      if (appender instanceof FileAppender) {
        info.setFile(((FileAppender)appender).getFile());
      } else if (appender instanceof AsyncAppender) {
        AsyncAppender aa = (AsyncAppender)appender;
        Iterator<Appender<ILoggingEvent>> iter = aa.iteratorForAppenders();
        List<AppenderInfo> asyncs = doGetLoggerAppenders(iter);
        // 标明异步appender
        List<String> nestedNames = new ArrayList<String>();
        for (AppenderInfo a : asyncs) {
          nestedNames.add(a.getName());
          result.add(a);
        }
        info.withDetail("nestedNames", nestedNames);
      } else if (appender instanceof ConsoleAppender) {
        info.withDetail("target", ((ConsoleAppender)appender).getTarget());
      }
      result.add(info);
    }

    return result;
  }
}

代码示例来源:origin: camunda/camunda-bpm-platform

@Override
protected void processPriorToRemoval(Appender<E> component) {
 component.stop();
}

代码示例来源:origin: ctripcorp/apollo

private void tryConfigCLogging() throws Exception {
 String appId = Foundation.app().getAppId();
 if (Strings.isNullOrEmpty(appId)) {
  logger.warn("App id is null or empty!");
  return;
 }
 LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory();
 Class clazz = Class.forName(cLoggingAppenderClass);
 Appender cLoggingAppender = (Appender) clazz.newInstance();
 ReflectionUtils.findMethod(clazz, "setAppId", String.class).invoke(cLoggingAppender, appId);
 ReflectionUtils.findMethod(clazz, "setServerIp", String.class)
   .invoke(cLoggingAppender, cloggingUrl());
 ReflectionUtils.findMethod(clazz, "setServerPort", int.class)
   .invoke(cLoggingAppender, Integer.parseInt(cloggingPort()));
 cLoggingAppender.setName("CentralLogging");
 cLoggingAppender.setContext(loggerContext);
 cLoggingAppender.start();
 ch.qos.logback.classic.Logger logger =
   (ch.qos.logback.classic.Logger) LoggerFactory.getLogger("root");
 logger.addAppender(cLoggingAppender);
}

代码示例来源: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: spring-projects/spring-security

private void redirectLogsTo(OutputStream os, Class<?> clazz) {
  Logger logger = (Logger) LoggerFactory.getLogger(clazz);
  Appender<ILoggingEvent> appender = mock(Appender.class);
  when(appender.isStarted()).thenReturn(true);
  doAnswer(writeTo(os)).when(appender).doAppend(any(ILoggingEvent.class));
  logger.addAppender(appender);
}

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

appender.stop();
appender.setContext(loggerContext);
appender.setName(output.getId());
filter.setContext(loggerContext);
filter.start();
appender.addFilter(filter);
appender.start();

代码示例来源:origin: camunda/camunda-bpm-platform

ch.qos.logback.core.Appender.class, context);
appender.setContext(context);
   + "].");
} else {
 appender.setName(appenderName);
 addInfo("Naming appender as [" + appenderName + "]");

代码示例来源:origin: tony19/logback-android

@Test
 public void testNoStart() {
  Appender<E> appender = getAppender();
  appender.setContext(context);
  appender.setName("doh");
  // is null OK?
  appender.doAppend(null);
  StatusChecker checker = new StatusChecker(context.getStatusManager());
  StatusPrinter.print(context);
  checker.assertContainsMatch("Attempted to append to non started appender \\[doh\\].");
 }
}

代码示例来源:origin: net.logstash.logback/logstash-logback-encoder

private void startDelegateAppenders() {
  for (Iterator<Appender<Event>> appenderIter = appenders.iteratorForAppenders(); appenderIter.hasNext();) {
    Appender<Event> appender = appenderIter.next();
    if (appender.getContext() == null) {
      appender.setContext(getContext());
    }
    if (!appender.isStarted()) {
      appender.start();
    }
  }
}

代码示例来源:origin: tony19/logback-android

@Test
public void testConfiguredAppender() {
 Appender<E> appender = getConfiguredAppender();
 appender.start();
 assertTrue(appender.isStarted());
  appender.stop();
 assertFalse(appender.isStarted());
 
}

代码示例来源:origin: protegeproject/protege

public void bind() {
    applyPreferences();
  Logger rootLogger = getRootLogger();
  appender.setContext(rootLogger.getLoggerContext());
  appender.start();		
  rootLogger.addAppender(appender);        
}

代码示例来源:origin: org.opendaylight.controller/logback-config

private void removeBeforeAppenders(final Set<ch.qos.logback.classic.Logger> loggersBefore, final LoggerTO logger,
    final ch.qos.logback.classic.Logger logbackLogger, final Optional<Set<Appender<ILoggingEvent>>> appendersBefore) {
  if (appendersBefore.isPresent()) {
    for (Appender<ILoggingEvent> appenderBefore : appendersBefore.get()) {
      logbackLogger.detachAppender(appenderBefore);
      appenderBefore.stop();
      LOG.trace("Logger {}: Removing old appender: {}", logger.getLoggerName(),
          appenderBefore.getName());
    }
    loggersBefore.remove(logbackLogger);
  }
}

代码示例来源:origin: qos-ch/logback-extensions

private Appender<ILoggingEvent> getDelegate() {
  ApplicationContext context = ApplicationContextHolder.getApplicationContext();
  try {
    @SuppressWarnings("unchecked")
    Appender<ILoggingEvent> appender = context.getBean(beanName, Appender.class);
    appender.setContext(getContext());
    if (!appender.isStarted()) {
      appender.start();
    }
    return appender;
  } catch (NoSuchBeanDefinitionException e) {
    stop();
    addError("The ApplicationContext does not contain an Appender named [" + beanName +
        "]. This delegating appender will now stop processing events.", e);
  }
  return null;
}

代码示例来源:origin: io.projectreactor/reactor-logback

private void startDelegateAppender() {
  Appender<ILoggingEvent> delegateAppender = delegate.get();
  if (null != delegateAppender && !delegateAppender.isStarted()) {
    delegateAppender.start();
  }
}

代码示例来源:origin: caskdata/cdap

@Override
public void start() {
 delegate.start();
}

代码示例来源:origin: camunda/camunda-bpm-platform

@Override
protected boolean isComponentStale(Appender<E> appender) {
 return !appender.isStarted();
}

代码示例来源:origin: caskdata/cdap

@Override
public void setContext(Context context) {
 delegate.setContext(context);
}

代码示例来源:origin: dCache/dcache

@Override
public void start()
{
  LoggerContext context = (LoggerContext) getContext();
  for (Logger logger: context.getLoggerList()) {
    RootFilterThresholds.setRoot(LoggerName.getInstance(logger.getName()), !logger.isAdditive());
  }
  for (Appender<ILoggingEvent> appender: getAppenders(context)) {
    String appenderName = appender.getName();
    RootFilterThresholds.addAppender(appenderName);
    for (Threshold threshold: _thresholds) {
      if (threshold.isApplicableToAppender(appender)) {
        RootFilterThresholds.setThreshold(
            threshold.getLogger(),
            appenderName,
            threshold.getLevel());
      }
    }
    CellThresholdFilterCompanion filter =
      new CellThresholdFilterCompanion(appenderName);
    filter.start();
    appender.addFilter(filter);
  }
  super.start();
}

代码示例来源:origin: net.logstash.logback/logstash-logback-encoder

private void stopDelegateAppenders() {
  for (Iterator<Appender<Event>> appenderIter = appenders.iteratorForAppenders(); appenderIter.hasNext();) {
    Appender<Event> appender = appenderIter.next();
    if (appender.isStarted()) {
      appender.stop();
    }
  }
}

相关文章