public static ThrowableProxyVO build(IThrowableProxy throwableProxy) { if (throwableProxy == null) { return null; } ThrowableProxyVO tpvo = new ThrowableProxyVO(); tpvo.className = throwableProxy.getClassName(); tpvo.message = throwableProxy.getMessage(); tpvo.commonFramesCount = throwableProxy.getCommonFrames(); tpvo.stackTraceElementProxyArray = throwableProxy.getStackTraceElementProxyArray(); IThrowableProxy cause = throwableProxy.getCause(); if (cause != null) { tpvo.cause = ThrowableProxyVO.build(cause); } IThrowableProxy[] suppressed = throwableProxy.getSuppressed(); if (suppressed != null) { tpvo.suppressed = new IThrowableProxy[suppressed.length]; for (int i = 0; i < suppressed.length; i++) { tpvo.suppressed[i] = ThrowableProxyVO.build(suppressed[i]); } } return tpvo; } }
private static void subjoinExceptionMessage(StringBuilder buf, IThrowableProxy tp) { buf.append(tp.getClassName()).append(": ").append(tp.getMessage()); } }
public void calculate(IThrowableProxy tp) { while (tp != null) { populateFrames(tp.getStackTraceElementProxyArray()); IThrowableProxy[] suppressed = tp.getSuppressed(); if (suppressed != null) { for (IThrowableProxy current : suppressed) { populateFrames(current.getStackTraceElementProxyArray()); } } tp = tp.getCause(); } }
public void printFirstLine(StringBuilder sb, IThrowableProxy tp) { int commonFrames = tp.getCommonFrames(); if (commonFrames > 0) { sb.append("<br />").append(CoreConstants.CAUSED_BY); } sb.append(tp.getClassName()).append(": ").append(Transform.escapeTags(tp.getMessage())); sb.append(CoreConstants.LINE_SEPARATOR); }
private static 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 + SUPPRESSED_EXCEPTION_INDENT, current); } } recursiveAppend(sb, CoreConstants.CAUSED_BY, indent, tp.getCause()); }
void render(StringBuilder sbuf, IThrowableProxy tp) { printFirstLine(sbuf, tp); int commonFrames = tp.getCommonFrames(); StackTraceElementProxy[] stepArray = tp.getStackTraceElementProxyArray(); for (int i = 0; i < stepArray.length - commonFrames; i++) { StackTraceElementProxy step = stepArray[i]; sbuf.append(TRACE_PREFIX); sbuf.append(Transform.escapeTags(step.toString())); sbuf.append(CoreConstants.LINE_SEPARATOR); } if (commonFrames > 0) { sbuf.append(TRACE_PREFIX); sbuf.append("\t... ").append(commonFrames).append(" common frames omitted").append(CoreConstants.LINE_SEPARATOR); } }
@Override protected boolean matchesSafely(IThrowableProxy item) { return exceptionClass.equals(item.getClassName()) && exceptionMessage.matches(item.getMessage().replace(System.lineSeparator(), "")) && item.getStackTraceElementProxyArray().length > 0; } }
@Override protected void postProcess(Object eventObject, OutputStream sw) { if (throwableExcluded) return; ILoggingEvent event = (ILoggingEvent) eventObject; IThrowableProxy tp = event.getThrowableProxy(); if (tp == null) return; String stackTracePrefix = stackTraceLayout.doLayout(event); boolean isRootException = true; while (tp != null) { StackTraceElementProxy[] stepArray = tp.getStackTraceElementProxyArray(); try { handleThrowableFirstLine(sw, tp, stackTracePrefix, isRootException); isRootException = false; for (StackTraceElementProxy step : stepArray) { StringBuilder sb = new StringBuilder(); sb.append(stackTracePrefix).append(step); sw.write(sb.toString().getBytes()); sw.flush(); } } catch (IOException e) { break; } tp = tp.getCause(); } }
private void printStackTraceIfAny(ILoggingEvent e) { IThrowableProxy throwableProxy = e.getThrowableProxy(); if (throwableProxy != null) { System.out.println(throwableProxy.getMessage()); for (StackTraceElementProxy el : throwableProxy.getStackTraceElementProxyArray()) { System.out.println("\t" + el); } } } }
public static void subjoinFirstLineRootCauseFirst(StringBuilder buf, IThrowableProxy tp) { if (tp.getCause() != null) { buf.append(CoreConstants.WRAPPED_BY); } subjoinExceptionMessage(buf, tp); }
StackTraceElementProxy[] stepArray = tp.getStackTraceElementProxyArray(); buf.append(" <log4j:throwable><![CDATA["); for (StackTraceElementProxy step : stepArray) {
/** * TODO: For better testability, consider making setDefaultUncaughtExceptionHandler pluggable or Spring configurable as an autowired list */ @Test public void testConstruction() throws InterruptedException { ListAppender<ILoggingEvent> inMemoryAppender = new ListAppender<>(); inMemoryAppender.start(); Logger logger = (Logger) LoggerFactory.getLogger("general"); try { logger.setLevel(Level.DEBUG); logger.addAppender(inMemoryAppender); // Registers the safety net new DefaultConfig(); // Trigger an exception in the background Executors.newSingleThreadExecutor().execute(new ExceptionThrower()); Thread.sleep(600); ILoggingEvent firstException = inMemoryAppender.list.get(0); assertEquals("Uncaught exception", firstException.getMessage()); IThrowableProxy cause = firstException.getThrowableProxy(); assertEquals("Unit test throwing an exception", cause.getMessage()); } finally { inMemoryAppender.stop(); logger.detachAppender(inMemoryAppender); } }
public static void subjoinFirstLine(StringBuilder buf, IThrowableProxy tp) { int commonFrames = tp.getCommonFrames(); if (commonFrames > 0) { buf.append(CoreConstants.CAUSED_BY); } subjoinExceptionMessage(buf, tp); }
private String determineClassName(IThrowableProxy throwable) { if (!useSimpleClassName) { return throwable.getClassName(); } if (throwable instanceof ThrowableProxy) { return ((ThrowableProxy) throwable).getThrowable().getClass().getSimpleName(); } String className = throwable.getClassName(); return className.substring(className.lastIndexOf('.') + 1); }
public void printFirstLine(StringBuilder sb, IThrowableProxy tp) { int commonFrames = tp.getCommonFrames(); if (commonFrames > 0) { sb.append("<br />").append(CoreConstants.CAUSED_BY); } sb.append(tp.getClassName()).append(": ").append( Transform.escapeTags(tp.getMessage())); sb.append(CoreConstants.LINE_SEPARATOR); }
private void subjoinExceptionMessage(StringBuilder buf, IThrowableProxy tp) { buf.append(tp.getClassName()).append(": ").append(tp.getMessage()); }
public void calculate(IThrowableProxy tp) { while (tp != null) { populateFrames(tp.getStackTraceElementProxyArray()); IThrowableProxy[] suppressed = tp.getSuppressed(); if(suppressed != null) { for(IThrowableProxy current:suppressed) { populateFrames(current.getStackTraceElementProxyArray()); } } tp = tp.getCause(); } }
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()); }
/** * @param sb The StringBuilder the STEPs are appended to. * @param indentLevel indentation level used for the STEPs, usually REGULAR_EXCEPTION_INDENT. * @param tp the IThrowableProxy containing the STEPs. */ public static void subjoinSTEPArray(StringBuilder sb, int indentLevel, IThrowableProxy tp) { StackTraceElementProxy[] stepArray = tp.getStackTraceElementProxyArray(); int commonFrames = tp.getCommonFrames(); for (int i = 0; i < stepArray.length - commonFrames; i++) { StackTraceElementProxy step = stepArray[i]; indent(sb, indentLevel); subjoinSTEP(sb, step); sb.append(CoreConstants.LINE_SEPARATOR); } if (commonFrames > 0) { indent(sb, indentLevel); sb.append("... ").append(commonFrames).append(" common frames omitted").append(CoreConstants.LINE_SEPARATOR); } }
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()); } }