@Override
  public byte[] encode(ILoggingEvent event) {
    StringBuilder sb = new StringBuilder();
    sb.append(OPEN_OBJ);
    var level = event.getLevel();
    if (level != null) {
      appenderMember(sb, "level", level.levelStr);
      sb.append(VALUE_SEPARATOR);
    }

    appenderMember(sb, "message", StringEscapeUtils.escapeJson(event.getFormattedMessage()));

    IThrowableProxy tp = event.getThrowableProxy();
    String stackTrace = null;
    if (tp != null) {
      sb.append(VALUE_SEPARATOR);
      stackTrace = tpc.convert(event);
      appenderMember(sb, "stacktrace", StringEscapeUtils.escapeJson(stackTrace));
    }

    sb.append(CLOSE_OBJ);
    sb.append(CoreConstants.JSON_LINE_SEPARATOR);
    return sb.toString().getBytes(UTF_8_CHARSET);
  }
@Test
  void should_encode_when_no_stacktrace() {
    var logEvent = mock(ILoggingEvent.class);
    when(logEvent.getLevel()).thenReturn(Level.DEBUG);
    when(logEvent.getFormattedMessage()).thenReturn("message");

    var bytes = underTest.encode(logEvent);

    assertThat(new String(bytes, StandardCharsets.UTF_8)).isEqualTo("{\"level\":\"DEBUG\",\"message\":\"message\"}\n");
  }