1
2
3
4
5
6
7
8
9
10
11
12
13
14 package ch.qos.logback.classic.pattern;
15
16 import ch.qos.logback.classic.spi.IThrowableProxy;
17 import ch.qos.logback.classic.spi.StackTraceElementProxy;
18 import ch.qos.logback.classic.spi.ThrowableProxyUtil;
19 import ch.qos.logback.core.CoreConstants;
20
21
22
23
24
25 public class RootCauseFirstThrowableProxyConverter extends ExtendedThrowableProxyConverter {
26
27 @Override
28 protected String throwableProxyToString(IThrowableProxy tp) {
29 StringBuilder buf = new StringBuilder(2048);
30 subjoinRootCauseFirst(tp, buf);
31 return buf.toString();
32 }
33
34 private void subjoinRootCauseFirst(IThrowableProxy tp, StringBuilder buf) {
35 if (tp.getCause() != null)
36 subjoinRootCauseFirst(tp.getCause(), buf);
37 subjoinRootCause(tp, buf);
38 }
39
40 private void subjoinRootCause(IThrowableProxy tp, StringBuilder buf) {
41 ThrowableProxyUtil.subjoinFirstLineRootCauseFirst(buf, tp);
42 buf.append(CoreConstants.LINE_SEPARATOR);
43 StackTraceElementProxy[] stepArray = tp.getStackTraceElementProxyArray();
44 int commonFrames = tp.getCommonFrames();
45
46 boolean unrestrictedPrinting = lengthOption > stepArray.length;
47
48
49 int maxIndex = (unrestrictedPrinting) ? stepArray.length : lengthOption;
50 if (commonFrames > 0 && unrestrictedPrinting) {
51 maxIndex -= commonFrames;
52 }
53
54 for (int i = 0; i < maxIndex; i++) {
55 String string = stepArray[i].toString();
56 buf.append(CoreConstants.TAB);
57 buf.append(string);
58 extraData(buf, stepArray[i]);
59 buf.append(CoreConstants.LINE_SEPARATOR);
60 }
61
62 }
63
64
65 }