private String getStackTraceFromEvent(ILoggingEvent logEvent) {
    IThrowableProxy throwable = logEvent.getThrowableProxy();
    if (null != throwable && null != throwable.getStackTraceElementProxyArray()) {
      StringBuilder sb = new StringBuilder();
      for (StackTraceElementProxy elt : throwable.getStackTraceElementProxyArray()) {
        sb.append(elt.toString());
        sb.append("\n");
      }
      return sb.toString();
    }

    if (logEvent.getCallerData() != null) {
      if (debug) {
        System.err.println(String.format("%s.append: falling back to appender stacktrace: ", this));
      }
      StringBuilder sb = new StringBuilder();
      for (StackTraceElement elt : logEvent.getCallerData()) {
        sb.append(elt);
        sb.append("\n");
      }
      return sb.toString();
    }

    return null;
  }
  @Test
  public void testAppendLoggingEvent() throws SQLException {
    ILoggingEvent event = createLoggingEvent();

    appender.append(event);
    StatusPrinter.printInCaseOfErrorsOrWarnings(lc);

    Statement stmt = connectionSource.getConnection().createStatement();
    ResultSet rs = null;
    rs = stmt.executeQuery("SELECT * FROM logging_event");
    if (rs.next()) {
      assertEquals(event.getTimeStamp(), rs.getLong(DBAppender.TIMESTMP_INDEX));
      assertEquals(event.getFormattedMessage(), rs.getString(DBAppender.FORMATTED_MESSAGE_INDEX));
      assertEquals(event.getLoggerName(), rs.getString(DBAppender.LOGGER_NAME_INDEX));
      assertEquals(event.getLevel().toString(), rs.getString(DBAppender.LEVEL_STRING_INDEX));
      assertEquals(event.getThreadName(), rs.getString(DBAppender.THREAD_NAME_INDEX));
      assertEquals(
          DBHelper.computeReferenceMask(event), rs.getShort(DBAppender.REFERENCE_FLAG_INDEX));
      assertEquals(String.valueOf(diff), rs.getString(DBAppender.ARG0_INDEX));
      StackTraceElement callerData = event.getCallerData()[0];
      assertEquals(callerData.getFileName(), rs.getString(DBAppender.CALLER_FILENAME_INDEX));
      assertEquals(callerData.getClassName(), rs.getString(DBAppender.CALLER_CLASS_INDEX));
      assertEquals(callerData.getMethodName(), rs.getString(DBAppender.CALLER_METHOD_INDEX));
    } else {
      fail("No row was inserted in the database");
    }

    rs.close();
    stmt.close();
  }
 @Override
 protected void append(ILoggingEvent event) {
   if (event == null || !isStarted()) return;
   if (includeCallerData) {
     event.getCallerData();
   }
   super.append(event);
 }
 private void stackTraceField(Map<String, Object> map, ILoggingEvent eventObject) {
   IThrowableProxy throwableProxy = eventObject.getThrowableProxy();
   if (throwableProxy != null) {
     StackTraceElementProxy[] proxyStackTraces = throwableProxy.getStackTraceElementProxyArray();
     if (proxyStackTraces != null && proxyStackTraces.length > 0) {
       StackTraceElement[] callStackTraces = eventObject.getCallerData();
       if (callStackTraces.length > 0) {
         StackTraceElement lastStack = callStackTraces[0];
         map.put("file", lastStack.getFileName());
         map.put("line", String.valueOf(lastStack.getLineNumber()));
       }
     }
   }
 }
  @Test
  public void settingIncludeCallerDataPropertyCausedCallerDataToBeIncluded() {
    asyncAppender.addAppender(listAppender);
    asyncAppender.setIncludeCallerData(true);
    asyncAppender.start();

    asyncAppender.doAppend(builder.build(diff));
    asyncAppender.stop();

    // check the event
    assertEquals(1, listAppender.list.size());
    ILoggingEvent e = listAppender.list.get(0);
    assertTrue(e.hasCallerData());
    StackTraceElement ste = e.getCallerData()[0];
    assertEquals(thisClassName, ste.getClassName());
  }