APISonar


com.google.common.flogger.backend.LoggerBackend.log

> com > google > common > flogger > backend > LoggerBackend > log
com APIs google APIs common APIs flogger APIs backend APIs LoggerBackend APIs log APIs

Example 1
private LoggerBackend backend;

  public void testWithThrown() {
    Throwable cause = new Throwable("Original Cause");
    backend.log(FakeLogData.of("Hello World").addMetadata(LogContext.Key.LOG_CAUSE, cause));

    assertLogCount(1);
    assertThrown(0, cause);
  }
Example 2
private LoggerBackend backend;

  public void testSimple() throws Exception {
    backend.log(FakeLogData.of("Hello World"));
    assertThat(getMessage(0)).isEqualTo("Hello World");
    assertLogEntry(0, INFO, "Hello World");
  }
Example 3
public void testErrorHandling() {
    AssertingLogger logger = getAssertingLogger();
    LoggerBackend backend = newBackend(logger);

    LogData data = FakeLogData.withPrintfStyle("Hello %?X World", "ignored");
    try {
      backend.log(data);
      fail("expected ParseException");
    } catch (ParseException expected) {
      logger.assertLogCount(0);
      backend.handleError(expected, data);
      logger.assertLogCount(1);
      assertThat(logger.getMessage(0)).contains("lo %[?]X Wo");
    }
  }
Example 4
public void testMessage() {
    AssertingLogger logger = getAssertingLogger();
    LoggerBackend backend = newBackend(logger);

    backend.log(FakeLogData.of("Hello World"));
    backend.log(FakeLogData.withPrintfStyle("Hello %s %s", "Foo", "Bar"));

    logger.assertLogCount(2);
    logger.assertLogEntry(0, INFO, "Hello World");
    logger.assertLogEntry(1, INFO, "Hello Foo Bar");
  }
Example 5
public void testRepeatedArguments() {
    AssertingLogger logger = new AssertingLogger();
    LoggerBackend backend = newBackend(logger);

    backend.log(withPrintfStyle("Printf: %1$d %1$d %1$d", 23));
    backend.log(withPrintfStyle("Printf: %d %<d %<d", 42));
    backend.log(withBraceStyle("Brace: {0} {0} {0}", 42));

    logger.assertLogCount(3);
    logger.assertLogEntry(0, INFO, "Printf: 23 23 23");
    logger.assertLogEntry(1, INFO, "Printf: 42 42 42");
    logger.assertLogEntry(2, INFO, "Brace: 42 42 42");
  }
Example 6
public void testMetadata() {
    AssertingLogger logger = getAssertingLogger();
    LoggerBackend backend = newBackend(logger);

    backend.log(
        FakeLogData.withPrintfStyle("Foo='%s'", "bar")
            .addMetadata(COUNT_KEY, 23)
            .addMetadata(ID_KEY, "test ID"));

    logger.assertLogCount(1);
    logger.assertLogEntry(0, INFO, "Foo='bar' [CONTEXT count=23 id=\"test ID\" ]");
  }