Java Code Examples for ch.qos.logback.classic.spi.IThrowableProxy#getSuppressed()

The following examples show how to use ch.qos.logback.classic.spi.IThrowableProxy#getSuppressed() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ExceptionUtil.java    From cloudwatch-logback-appender with Apache License 2.0 6 votes vote down vote up
private static void appendProxy(StringBuilder sb, String aPrefix, String aHeader, IThrowableProxy aException) {

        sb.append(aPrefix + aHeader + aException.getClassName() + ": " +aException.getMessage() + "\n");

        String prefix = aPrefix+"\t";
        appendStackTrace(sb, prefix, aException);

        IThrowableProxy[] suppressed = aException.getSuppressed();
        if(suppressed!=null) {
            for(IThrowableProxy supp : suppressed) {
                if(supp!=null) {
                    appendProxy(sb, prefix, "Suppressed: ", supp);
                }
            }
        }

        IThrowableProxy cause = aException.getCause();
        if(cause!=null) {
            appendProxy(sb, prefix, "Causd by: ", cause);
        }
    }
 
Example 2
Source File: StructuredLoggingEncoder.java    From flo with Apache License 2.0 6 votes vote down vote up
private static void writeStack(StringBuilder sb, IThrowableProxy t, String caption, int indent, String linebreak) {
  if (t == null) {
    return;
  }
  indent(sb, indent).append(caption).append(t.getClassName()).append(": ").append(t.getMessage()).append(linebreak);
  final StackTraceElementProxy[] trace = t.getStackTraceElementProxyArray();
  if (trace != null) {
    int commonFrames = t.getCommonFrames();
    int printFrames = trace.length - commonFrames;
    for (int i = 0; i < printFrames; i++) {
      indent(sb, indent).append("\t").append(trace[i]).append(linebreak);
    }
    if (commonFrames != 0) {
      indent(sb, indent).append("\t... ").append(commonFrames).append(" more").append(linebreak);
    }
    final IThrowableProxy[] suppressed = t.getSuppressed();
    for (IThrowableProxy st : suppressed) {
      writeStack(sb, st, "Suppressed: ", indent + 1, linebreak);
    }
  }

  writeStack(sb, t.getCause(), "Caused by: ", indent, linebreak);
}
 
Example 3
Source File: CollectorLogbackAppender.java    From glowroot with Apache License 2.0 6 votes vote down vote up
private static Proto.Throwable toProto(IThrowableProxy t) {
    Proto.Throwable.Builder builder = Proto.Throwable.newBuilder()
            .setClassName(t.getClassName());
    String message = t.getMessage();
    if (message != null) {
        builder.setMessage(message);
    }
    for (StackTraceElementProxy element : t.getStackTraceElementProxyArray()) {
        builder.addStackTraceElement(ErrorMessage.toProto(element.getStackTraceElement()));
    }
    builder.setFramesInCommonWithEnclosing(t.getCommonFrames());
    IThrowableProxy cause = t.getCause();
    if (cause != null) {
        builder.setCause(toProto(cause));
    }
    for (IThrowableProxy suppressed : t.getSuppressed()) {
        builder.addSuppressed(toProto(suppressed));
    }
    return builder.build();
}
 
Example 4
Source File: NSThrowableConvert.java    From ns4_frame with Apache License 2.0 5 votes vote down vote up
private void recursiveAppend(StringBuilder sb, String prefix, int indent, IThrowableProxy tp) {
    if(tp == null)
        return;
    subjoinFirstLine(sb, prefix, indent, tp);
    sb.append(CoreConstants.LINE_SEPARATOR);
    subjoinSTEPArray(sb, indent, tp);
    IThrowableProxy[] suppressed = tp.getSuppressed();
    if(suppressed != null) {
        for(IThrowableProxy current : suppressed) {
            recursiveAppend(sb, CoreConstants.SUPPRESSED, indent + ThrowableProxyUtil.SUPPRESSED_EXCEPTION_INDENT, current);
        }
    }
    recursiveAppend(sb, CoreConstants.CAUSED_BY, indent, tp.getCause());
}
 
Example 5
Source File: MillisecondPrecisionSyslogAppender.java    From logging-java with Apache License 2.0 5 votes vote down vote up
private void recursiveWrite(
    final OutputStream sw,
    final String stackTracePrefix,
    final IThrowableProxy tp,
    final int indent,
    final String firstLinePrefix) {
  final StackTraceElementProxy[] stepArray = tp.getStackTraceElementProxyArray();
  try {
    handleThrowableFirstLine(sw, tp, stackTracePrefix, indent, firstLinePrefix);
    for (final StackTraceElementProxy step : stepArray) {
      final StringBuilder sb = new StringBuilder();
      sb.append(stackTracePrefix);
      addIndent(sb, indent);
      sb.append(step);
      sw.write(sb.toString().getBytes());
      sw.flush();
    }
  } catch (IOException e) {
    return;
  }

  final IThrowableProxy[] suppressed = tp.getSuppressed();
  if (suppressed != null) {
    for (final IThrowableProxy current : suppressed) {
      recursiveWrite(sw, stackTracePrefix, current, indent + 1, CoreConstants.SUPPRESSED);
    }
  }

  final IThrowableProxy cause = tp.getCause();
  if (cause != null) {
    recursiveWrite(sw, stackTracePrefix, cause, indent, CoreConstants.CAUSED_BY);
  }
}