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;
  }
Ejemplo n.º 2
0
 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()));
       }
     }
   }
 }
Ejemplo n.º 3
0
  private String createStackTrace(final ILoggingEvent eventObject) {

    final IThrowableProxy tp = eventObject.getThrowableProxy();
    if (tp != null) {
      final StringBuilder stringBuilder =
          new StringBuilder(tp.getClassName()).append(": ").append(tp.getMessage());
      for (final StackTraceElementProxy stackTraceLine : tp.getStackTraceElementProxyArray()) {
        stringBuilder.append(stackTraceLine.toString()).append("\n");
      }

      return stringBuilder.toString();
    }
    return null;
  }
  @Override
  protected void append(ILoggingEvent p) {
    if (!enable || eventWriter == null || !eventWriter.isEnable()) {
      return;
    }

    Level logLevel = p.getLevel();
    if (logLevel.toInt() < minimumLevel) {
      return;
    }

    RecordEventSummary eventInfo = new RecordEventSummary(-1);

    eventInfo.setEventType(eventType);
    eventInfo.setThreadName(p.getThreadName());
    eventInfo.setEventDate(new Date(p.getTimeStamp()));
    eventInfo.setEventClassName(p.getLoggerName());
    eventInfo.setEventMethodName(logLevel.toString().toLowerCase());

    // use message instead of formattedMessage for header!!
    // => use "... {0} .. {1} .." to compress event summary encoding
    eventInfo.setEventMethodDetail(p.getMessage());

    if (!eventWriter.isEnable(eventInfo)) {
      return;
    }

    LogbackEventData eventData = new LogbackEventData();
    eventData.setLevel(eventInfo, logLevel.toString());
    eventData.setFormattedMessage(p.getFormattedMessage());
    eventData.setArgumentArray(p.getArgumentArray());

    if (p.getThrowableProxy() != null) {
      IThrowableProxy throwableProxy = p.getThrowableProxy();
      // throwableProxy.getClassName()
      // throwableProxy.getMessage()
      StackTraceElementProxy[] traceElts = throwableProxy.getStackTraceElementProxyArray();
      eventData.setStackTraceElements(traceElts);
    }

    Map<String, String> mdcPropertyMap = p.getMDCPropertyMap();
    if (mdcPropertyMap != null && !mdcPropertyMap.isEmpty()) {
      eventData.setMDCPropertyMap(mdcPropertyMap);
    }

    eventWriter.addEvent(eventInfo, eventData, null);
  }