ch.qos.logback.core.Appender.doAppend()方法的使用及代码示例

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

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

Appender.doAppend介绍

[英]This is where an appender accomplishes its work. Note that the argument is of type Object.
[中]这是appender完成其工作的地方。请注意,参数的类型为Object。

代码示例

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

@Test
public void requestWhenDebugSetToFalseThenDoesNotLogDebugInformation() throws Exception {
  Appender<ILoggingEvent> appender = mockAppenderFor("Spring Security Debugger");
  this.spring.register(NoDebugWebSecurity.class).autowire();
  this.mvc.perform(get("/"));
  assertThat(filterChainClass()).isNotEqualTo(DebugFilter.class);
  verify(appender, never()).doAppend(any(ILoggingEvent.class));
}

代码示例来源:origin: spring-projects/spring-security

@Test
public void requestWhenDebugSetToTrueThenLogsDebugInformation() throws Exception {
  Appender<ILoggingEvent> appender = mockAppenderFor("Spring Security Debugger");
  this.spring.register(DebugWebSecurity.class).autowire();
  this.mvc.perform(get("/"));
  assertThat(filterChainClass()).isEqualTo(DebugFilter.class);
  verify(appender, atLeastOnce()).doAppend(any(ILoggingEvent.class));
}

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

/**
 * Call the <code>doAppend</code> method on all attached appenders.
 */
public int appendLoopOnAppenders(E e) {
 int size = 0;
  for (Appender<E> appender : appenderList) {
   appender.doAppend(e);
   size++;
  }
 return size;
}

代码示例来源:origin: palantir/atlasdb

@Test
public void dropTableTraceLogPresentOnTraceLevelEvenIfQueryIsSlow() {
  Appender mockAppender = setLogLevelAndGetAppender(Level.TRACE);
  doAnswer(waitASecondAndAHalf).when(delegate).dropTable(any());
  kvs.dropTable(TABLE_REF);
  verify(mockAppender).doAppend(traceLogMatcher.get());
  verify(mockAppender).doAppend(slowLogMatcher.get());
}

代码示例来源:origin: palantir/atlasdb

@Test
public void getAllTableNamesTraceLogPresentOnTraceLevelEvenIfQueryIsSlow() {
  Appender mockAppender = setLogLevelAndGetAppender(Level.TRACE);
  doAnswer(waitASecondAndAHalf).when(delegate).getAllTableNames();
  kvs.getAllTableNames();
  verify(mockAppender).doAppend(traceLogMatcher.get());
  verify(mockAppender).doAppend(slowLogMatcher.get());
}

代码示例来源:origin: palantir/atlasdb

@Test
public void getTraceLogPresentOnTraceLevelEvenIfQueryIsSlow() {
  Appender mockAppender = setLogLevelAndGetAppender(Level.TRACE);
  doAnswer(waitASecondAndAHalfAndReturn).when(delegate).get(TABLE_REF, timestampByCell);
  kvs.get(TABLE_REF, timestampByCell);
  verify(mockAppender).doAppend(traceLogMatcher.get());
  verify(mockAppender).doAppend(slowLogMatcher.get());
}

代码示例来源:origin: jbake-org/jbake

@Test
public void shouldLogSkipCopyingSingleFileIfDirectory() throws IOException {
  Asset asset = new Asset(config);
  File emptyDir = new File(folder.toFile(),"emptyDir");
  emptyDir.mkdir();
  asset.copySingleFile(emptyDir);
  verify(mockAppender, times(1)).doAppend(captorLoggingEvent.capture());
  LoggingEvent loggingEvent = captorLoggingEvent.getValue();
  assertThat(loggingEvent.getMessage()).isEqualTo("Skip copying single asset file [{}]. Is a directory.");
}

代码示例来源:origin: palantir/atlasdb

@Test
public void dropTableSlowLogPresentOnInfoLevel() {
  Appender mockAppender = setLogLevelAndGetAppender(Level.INFO);
  doAnswer(waitASecondAndAHalf).when(delegate).dropTable(any());
  kvs.dropTable(TABLE_REF);
  verify(mockAppender).doAppend(slowLogMatcher.get());
}

代码示例来源:origin: jbake-org/jbake

@Test
public void shouldLogWarningIfDocumentTypeNotFound() throws Exception {
  File sourceFolder = TestUtils.getTestResourcesAsSourceFolder();
  JBakeConfiguration config = util.loadConfig(sourceFolder);
  config.getTemplateFileByDocType("none");
  verify(mockAppender, times(1)).doAppend(captorLoggingEvent.capture());
  LoggingEvent loggingEvent = captorLoggingEvent.getValue();
  assertThat(loggingEvent.getMessage()).isEqualTo("Cannot find configuration key '{}' for document type '{}'");
}

代码示例来源:origin: palantir/atlasdb

@Test
public void getAllTableNamesSlowLogPresentOnInfoLevel() {
  Appender mockAppender = setLogLevelAndGetAppender(Level.INFO);
  doAnswer(waitASecondAndAHalf).when(delegate).getAllTableNames();
  kvs.getAllTableNames();
  verify(mockAppender).doAppend(slowLogMatcher.get());
}

代码示例来源:origin: palantir/atlasdb

@Test
public void getTraceLogPresentOnTraceLevel() {
  Appender mockAppender = setLogLevelAndGetAppender(Level.TRACE);
  kvs.get(TABLE_REF, timestampByCell);
  verify(mockAppender).doAppend(traceLogMatcher.get());
}

代码示例来源:origin: jbake-org/jbake

@Test
public void shouldLogAWarningIfAsciidocOptionCouldNotBeFound() throws Exception {
  File sourceFolder = TestUtils.getTestResourcesAsSourceFolder();
  DefaultJBakeConfiguration config = (DefaultJBakeConfiguration) util.loadConfig(sourceFolder);
  config.getAsciidoctorOption("template_dirs");
  verify(mockAppender, times(1)).doAppend(captorLoggingEvent.capture());
  LoggingEvent loggingEvent = captorLoggingEvent.getValue();
  assertThat(loggingEvent.getMessage()).isEqualTo("Cannot find asciidoctor option '{}.{}'");
}

代码示例来源:origin: palantir/atlasdb

@Test
public void getSlowLogPresentOnInfoLevel() {
  Appender mockAppender = setLogLevelAndGetAppender(Level.INFO);
  doAnswer(waitASecondAndAHalfAndReturn).when(delegate).get(TABLE_REF, timestampByCell);
  kvs.get(TABLE_REF, timestampByCell);
  verify(mockAppender).doAppend(slowLogMatcher.get());
}

代码示例来源:origin: palantir/atlasdb

@Test
public void dropTableTraceLogPresentOnTraceLevel() {
  Appender mockAppender = setLogLevelAndGetAppender(Level.TRACE);
  kvs.dropTable(TABLE_REF);
  verify(mockAppender).doAppend(traceLogMatcher.get());
}

代码示例来源:origin: palantir/atlasdb

@Test
public void getAllTableNamesTraceLogPresentOnTraceLevel() {
  Appender mockAppender = setLogLevelAndGetAppender(Level.TRACE);
  kvs.getAllTableNames();
  verify(mockAppender).doAppend(traceLogMatcher.get());
}

代码示例来源:origin: jbake-org/jbake

@Test
public void shouldLogWarningIfAssetFolderDoesNotExist() throws Exception {
  String contentFolderName = "content";
  String templateFolderName = "template";
  String destinationFolderName = "output";
  String assetFolderName = "assets";
  File templateFolder = TestUtils.newFolder(folder.toFile(), templateFolderName);
  File contentFolder = TestUtils.newFolder(folder.toFile(), contentFolderName);
  File destinationFolder = TestUtils.newFolder(folder.toFile(), destinationFolderName);
  File assetFolder = new File(folder.toFile(), assetFolderName);
  JBakeConfiguration configuration = mock(JBakeConfiguration.class);
  when(configuration.getSourceFolder()).thenReturn(folder.toFile());
  when(configuration.getTemplateFolder()).thenReturn(templateFolder);
  when(configuration.getTemplateFolderName()).thenReturn(templateFolderName);
  when(configuration.getContentFolder()).thenReturn(contentFolder);
  when(configuration.getContentFolderName()).thenReturn(contentFolderName);
  when(configuration.getDestinationFolder()).thenReturn(destinationFolder);
  when(configuration.getAssetFolder()).thenReturn(assetFolder);
  JBakeConfigurationInspector inspector = new JBakeConfigurationInspector(configuration);
  inspector.inspect();
  verify(mockAppender, times(1)).doAppend(captorLoggingEvent.capture());
  LoggingEvent loggingEvent = captorLoggingEvent.getValue();
  assertThat(loggingEvent.getMessage()).isEqualTo("No asset folder '{}' was found!");
  assertThat(loggingEvent.getFormattedMessage()).isEqualTo("No asset folder '" + assetFolder.getAbsolutePath() + "' was found!");
}

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

@Override
protected void append(E event) {
 if (!isStarted()) {
  return;
 }
 String discriminatingValue = discriminator.getDiscriminatingValue(event);
 long timestamp = getTimestamp(event);
 Appender<E> appender = appenderTracker.getOrCreate(discriminatingValue, timestamp);
 // marks the appender for removal as specified by the user
 if (eventMarksEndOfLife(event)) {
  appenderTracker.endOfLife(discriminatingValue);
 }
 appenderTracker.removeStaleComponents(timestamp);
 appender.doAppend(event);
}

代码示例来源: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\\].");
 }
}

相关文章