ch.qos.logback.classic.spi.StackTraceElementProxy Java Examples

The following examples show how to use ch.qos.logback.classic.spi.StackTraceElementProxy. 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 Project: bither-desktop-java   Author: bither   File: PrefixedThrowableProxyConverter.java    License: Apache License 2.0 6 votes vote down vote up
void subjoinThrowableProxy(StringBuilder buf, IThrowableProxy tp) {
    subjoinFirstLine(buf, tp);


    buf.append(CoreConstants.LINE_SEPARATOR);
    final StackTraceElementProxy[] stepArray = tp.getStackTraceElementProxyArray();
    final int commonFrames = tp.getCommonFrames();

    int maxIndex = stepArray.length;
    if (commonFrames > 0) {
        maxIndex -= commonFrames;
    }

    for (int i = 0; i < maxIndex; i++) {
        final String string = stepArray[i].toString();
        buf.append(PREFIX);
        buf.append(string);
        extraData(buf, stepArray[i]); // allow other data to be added
        buf.append(CoreConstants.LINE_SEPARATOR);
    }

    if (commonFrames > 0) {
        buf.append("!... ").append(tp.getCommonFrames()).append(
                " common frames omitted").append(CoreConstants.LINE_SEPARATOR);
    }
}
 
Example #2
Source Project: flo   Author: spotify   File: StructuredLoggingEncoder.java    License: 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 Project: glowroot   Author: glowroot   File: CollectorLogbackAppender.java    License: 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 Project: bither-desktop-java   Author: bither   File: PrefixedThrowableProxyConverter.java    License: Apache License 2.0 6 votes vote down vote up
void subjoinThrowableProxy(StringBuilder buf, IThrowableProxy tp) {
    subjoinFirstLine(buf, tp);


    buf.append(CoreConstants.LINE_SEPARATOR);
    final StackTraceElementProxy[] stepArray = tp.getStackTraceElementProxyArray();
    final int commonFrames = tp.getCommonFrames();

    int maxIndex = stepArray.length;
    if (commonFrames > 0) {
        maxIndex -= commonFrames;
    }

    for (int i = 0; i < maxIndex; i++) {
        final String string = stepArray[i].toString();
        buf.append(PREFIX);
        buf.append(string);
        extraData(buf, stepArray[i]); // allow other data to be added
        buf.append(CoreConstants.LINE_SEPARATOR);
    }

    if (commonFrames > 0) {
        buf.append("!... ").append(tp.getCommonFrames()).append(
                " common frames omitted").append(CoreConstants.LINE_SEPARATOR);
    }
}
 
Example #5
Source Project: elexis-3-core   Author: elexis   File: IntegrationPostHandler.java    License: Eclipse Public License 1.0 6 votes vote down vote up
private String parseException(ILoggingEvent eventObject2){
	if (eventObject.getThrowableProxy() != null) {
		StringBuilder sbException = new StringBuilder();
		IThrowableProxy throwableProxy = eventObject.getThrowableProxy();
		
		sbException.append("```\n");
		StackTraceElementProxy[] st = throwableProxy.getStackTraceElementProxyArray();
		for (int j = 0; j < st.length; j++) {
			StackTraceElementProxy stackTraceElementProxy = st[j];
			StackTraceElement stackTraceElement = stackTraceElementProxy.getStackTraceElement();
			sbException.append(stackTraceElement + "\n");
			if (j == 5) {
				break;
			}
		}
		sbException.append("```");
		return sbException.toString();
	}
	return null;
}
 
Example #6
Source Project: ns4_frame   Author: newsettle   File: NSThrowableConvert.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void subjoinSTEPArray(StringBuilder buf, int indent, IThrowableProxy tp) {
    String totalKey = LogKey.getTotalKey();
    StackTraceElementProxy[] stepArray = tp.getStackTraceElementProxyArray();
    int commonFrames = tp.getCommonFrames();

    boolean unrestrictedPrinting = Integer.MAX_VALUE > stepArray.length;


    int maxIndex = (unrestrictedPrinting) ? stepArray.length : Integer.MAX_VALUE;
    if (commonFrames > 0 && unrestrictedPrinting) {
        maxIndex -= commonFrames;
    }

    for (int i = 0; i < maxIndex; i++) {
        buf.append(totalKey);
        ThrowableProxyUtil.indent(buf, indent);
        buf.append(stepArray[i]);
        extraData(buf, stepArray[i]); // allow other data to be added
        buf.append(CoreConstants.LINE_SEPARATOR);
    }

    if (commonFrames > 0 && unrestrictedPrinting) {
        buf.append(totalKey);
        ThrowableProxyUtil.indent(buf, indent);
        buf.append("... ").append(tp.getCommonFrames()).append(
                " common frames omitted").append(CoreConstants.LINE_SEPARATOR);
    }
}
 
Example #7
Source Project: aliyun-log-logback-appender   Author: aliyun   File: LoghubAppender.java    License: Apache License 2.0 5 votes vote down vote up
private String fullDump(StackTraceElementProxy[] stackTraceElementProxyArray) {
    StringBuilder builder = new StringBuilder();
    for (StackTraceElementProxy step : stackTraceElementProxyArray) {
        builder.append(CoreConstants.LINE_SEPARATOR);
        String string = step.toString();
        builder.append(CoreConstants.TAB).append(string);
        ThrowableProxyUtil.subjoinPackagingData(builder, step);
    }
    return builder.toString();
}
 
Example #8
Source Project: cloudwatch-logback-appender   Author: dibog   File: ExceptionUtil.java    License: Apache License 2.0 5 votes vote down vote up
private  static void appendStackTrace(StringBuilder sb, String prefix, IThrowableProxy aProxy) {

        StackTraceElementProxy[] frames = aProxy.getStackTraceElementProxyArray();
        int commonFrames = aProxy.getCommonFrames();
        for(int i=0, size=frames.length-commonFrames; i<size; ++i) {
            sb.append(prefix+frames[i]+"\n");
        }
        if (commonFrames>0) {
            sb.append(prefix+"... "+commonFrames+" more"+"\n");
        }
    }
 
Example #9
Source Project: styx   Author: HotelsDotCom   File: ExceptionConverter.java    License: Apache License 2.0 5 votes vote down vote up
private String getExceptionData(final ILoggingEvent loggingEvent) {
    IThrowableProxy throwableProxy = loggingEvent.getThrowableProxy();
    StackTraceElementProxy loggableStackTraceElement =
            findFirstStackTraceElementForClasses(throwableProxy, readStyxClassesFromProperty())
                    .orElse(getTopStackTraceElement(throwableProxy));

    return Optional.ofNullable(loggableStackTraceElement)
            .map(ExceptionConverter::createExceptionMessage)
            .orElse(NO_MSG);
}
 
Example #10
Source Project: styx   Author: HotelsDotCom   File: ExceptionConverter.java    License: Apache License 2.0 5 votes vote down vote up
private StackTraceElementProxy getTopStackTraceElement(final IThrowableProxy throwableProxy) {
    StackTraceElementProxy stackTraceLine = null;
    StackTraceElementProxy[] stackTraceElementProxyArray = throwableProxy.getStackTraceElementProxyArray();
    if (stackTraceElementProxyArray != null && stackTraceElementProxyArray.length > 0) {
        stackTraceLine = stackTraceElementProxyArray[0];
    }
    return stackTraceLine;
}
 
Example #11
Source Project: cloudwatchlogs-java-appender   Author: boxfuse   File: CloudwatchLogsLogbackAppender.java    License: Apache License 2.0 5 votes vote down vote up
private String dump(IThrowableProxy throwableProxy) {
    StringBuilder builder = new StringBuilder();
    builder.append(throwableProxy.getClassName()).append(": ").append(throwableProxy.getMessage()).append(CoreConstants.LINE_SEPARATOR);
    for (StackTraceElementProxy step : throwableProxy.getStackTraceElementProxyArray()) {
        String string = step.toString();
        builder.append(CoreConstants.TAB).append(string);
        ThrowableProxyUtil.subjoinPackagingData(builder, step);
        builder.append(CoreConstants.LINE_SEPARATOR);
    }
    return builder.toString();
}
 
Example #12
Source Project: twill   Author: apache   File: DefaultLogThrowable.java    License: Apache License 2.0 5 votes vote down vote up
DefaultLogThrowable(IThrowableProxy throwableProxy) {
  this.className = throwableProxy.getClassName();
  this.message = throwableProxy.getMessage();

  StackTraceElementProxy[] stackTraceElementProxyArray = throwableProxy.getStackTraceElementProxyArray();
  this.stackTraces = new StackTraceElement[stackTraceElementProxyArray.length];
  for (int i = 0; i < stackTraceElementProxyArray.length; i++) {
    stackTraces[i] = stackTraceElementProxyArray[i].getStackTraceElement();
  }

  cause = (throwableProxy.getCause() == null) ? null : new DefaultLogThrowable(throwableProxy.getCause());
}
 
Example #13
Source Project: otroslogviewer   Author: otros-systems   File: LogbackUtil.java    License: Apache License 2.0 5 votes vote down vote up
public static void addException(IThrowableProxy throwableProxy, String message, LogDataBuilder builder) {
  if (throwableProxy != null) {
    StringBuilder sb = new StringBuilder();
    sb.append(message).append("\n");
    sb.append(throwableProxy.getClassName()).append(": ").append(throwableProxy.getMessage()).append("\n");

    for (StackTraceElementProxy stackTraceElementProxy : throwableProxy.getStackTraceElementProxyArray()) {
      sb.append("\t").append(stackTraceElementProxy.getSTEAsString()).append("\n");
    }
    builder.withMessage(sb.toString());
  }
}
 
Example #14
Source Project: rollbar-java   Author: rollbar   File: RollbarAppender.java    License: MIT License 5 votes vote down vote up
private StackTraceElement[] buildStackTraceElements(StackTraceElementProxy[] stackTraceElements) {
  StackTraceElement[] elements = new StackTraceElement[stackTraceElements.length];

  for (int i = 0; i < stackTraceElements.length; i++) {
    elements[i] = stackTraceElements[i].getStackTraceElement();
  }

  return elements;
}
 
Example #15
Source Project: brooklyn-server   Author: apache   File: LogWatcher.java    License: Apache License 2.0 5 votes vote down vote up
public static Predicate<ILoggingEvent> containsExceptionStackLine(final Class<?> clazz, final String methodName) {
    return event -> {
        IThrowableProxy throwable = (event != null) ? event.getThrowableProxy() : null;
        if (throwable != null) {
            for (StackTraceElementProxy line : throwable.getStackTraceElementProxyArray()) {
                if (line.getStackTraceElement().getClassName().contains(clazz.getSimpleName())
                        && line.getStackTraceElement().getMethodName().contains(methodName)) {
                    return true;
                }
            }
        }
        return false;
    };
}
 
Example #16
Source Project: brooklyn-server   Author: apache   File: LogWatcher.java    License: Apache License 2.0 5 votes vote down vote up
public void printEvents(PrintStream stream, Iterable<? extends ILoggingEvent> events) {
    for (ILoggingEvent event : events) {
        stream.println(Time.makeDateString(event.getTimeStamp()) + ": " + event.getThreadName()
                + ": " + event.getLevel() + ": " + event.getMessage());
        IThrowableProxy throwable = event.getThrowableProxy();
        if (throwable != null) {
            stream.println("\t" + throwable.getMessage());
            if (throwable.getStackTraceElementProxyArray() != null) {
                for (StackTraceElementProxy element : throwable.getStackTraceElementProxyArray()) {
                    stream.println("\t\t" + "at " + element);
                }
            }
        }
    }
}
 
Example #17
Source Project: logging-java   Author: spotify   File: MillisecondPrecisionSyslogAppender.java    License: 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);
  }
}
 
Example #18
Source Project: qiniu-logging-plugin   Author: qiniu   File: LogbackQiniuAppender.java    License: BSD 2-Clause "Simplified" License 4 votes vote down vote up
protected void append(ILoggingEvent logEvent) {
    Point point = new Point();
    point.append("timestamp", logEvent.getTimeStamp());
    point.append("level", logEvent.getLevel().toString());
    point.append("logger", logEvent.getLoggerName());

    if (logEvent.getMarker() != null) {
        point.append("marker", logEvent.getMarker().toString());
    } else {
        point.append("marker", "");
    }

    point.append("message", logEvent.getMessage());
    point.append("thread_name", logEvent.getThreadName());
    point.append("thread_id", 0); // logback doest not support thread id
    point.append("thread_priority", 0);
    if (logEvent.getThrowableProxy() != null) {
        StringBuilder exceptionBuilder = new StringBuilder();
        exceptionBuilder.append(logEvent.getThrowableProxy().getMessage()).append("\n");
        for (StackTraceElementProxy proxy : logEvent.getThrowableProxy().getStackTraceElementProxyArray()) {
            exceptionBuilder.append(proxy.getStackTraceElement().toString()).append("\n");
        }
        point.append("exception", exceptionBuilder.toString());
    } else {
        point.append("exception", "");
    }

    //lock
    this.rwLock.lock();
    if (!batch.canAdd(point)) {

        final byte[] postBody = batch.toString().getBytes(Constants.UTF_8);
        try {
            this.executorService.execute(new Runnable() {
                public void run() {
                    try {
                        Response response = logPushSender.send(postBody);
                        response.close();
                    } catch (QiniuException e) {
                        //e.printStackTrace();
                        guard.write(postBody);
                    }
                }
            });
        } catch (RejectedExecutionException ex) {
            guard.write(postBody);
        }

        batch.clear();
    }
    batch.add(point);
    this.rwLock.unlock();
}
 
Example #19
Source Project: styx   Author: HotelsDotCom   File: ExceptionConverter.java    License: Apache License 2.0 4 votes vote down vote up
private static String createExceptionMessage(StackTraceElementProxy loggableStackTraceElement) {
    String exceptionClass = loggableStackTraceElement.getStackTraceElement().getClassName();
    String exceptionMethod = loggableStackTraceElement.getStackTraceElement().getMethodName();
    String exceptionID = hashCodeForException(exceptionClass, exceptionMethod);
    return MessageFormat.format(SPLUNK_FRIENDLY_LOG_MESSAGE_TEMPLATE, exceptionClass, exceptionMethod, exceptionID);
}
 
Example #20
Source Project: styx   Author: HotelsDotCom   File: ExceptionConverter.java    License: Apache License 2.0 4 votes vote down vote up
private Optional<StackTraceElementProxy> findFirstStackTraceElementForClasses(final IThrowableProxy throwableProxy, final String[] targetClasses) {
    return StreamSupport.stream(collectThrowableProxies(throwableProxy).spliterator(), false)
            .flatMap(proxy -> proxy != null ? Arrays.stream(proxy.getStackTraceElementProxyArray()) : Stream.empty())
            .filter(steProxy -> contains(steProxy.getSTEAsString(), targetClasses))
            .findFirst();
}
 
Example #21
Source Project: pravega   Author: pravega   File: MetricsLogAppenderTests.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public StackTraceElementProxy[] getStackTraceElementProxyArray() {
    return new StackTraceElementProxy[0];
}
 
Example #22
Source Project: bither-desktop-java   Author: bither   File: PrefixedExtendedThrowableProxyConverter.java    License: Apache License 2.0 4 votes vote down vote up
@Override
protected void extraData(StringBuilder builder, StackTraceElementProxy step) {
    if (step != null) {
        ThrowableProxyUtil.subjoinPackagingData(builder, step);
    }
}
 
Example #23
Source Project: bither-desktop-java   Author: bither   File: PrefixedExtendedThrowableProxyConverter.java    License: Apache License 2.0 4 votes vote down vote up
@Override
protected void extraData(StringBuilder builder, StackTraceElementProxy step) {
    if (step != null) {
        ThrowableProxyUtil.subjoinPackagingData(builder, step);
    }
}