1
2
3
4
5
6
7
8
9
10
11
12
13
14 package ch.qos.logback.classic.html;
15
16 import ch.qos.logback.classic.spi.ILoggingEvent;
17 import ch.qos.logback.classic.spi.IThrowableProxy;
18 import ch.qos.logback.classic.spi.StackTraceElementProxy;
19 import ch.qos.logback.core.CoreConstants;
20 import ch.qos.logback.core.helpers.Transform;
21 import ch.qos.logback.core.html.IThrowableRenderer;
22
23 public class DefaultThrowableRenderer implements IThrowableRenderer<ILoggingEvent> {
24
25 static final String TRACE_PREFIX = "<br /> ";
26
27 public void render(StringBuilder sbuf, ILoggingEvent event) {
28 IThrowableProxy tp = event.getThrowableProxy();
29 sbuf.append("<tr><td class=\"Exception\" colspan=\"6\">");
30 while (tp != null) {
31 render(sbuf, tp);
32 tp = tp.getCause();
33 }
34 sbuf.append("</td></tr>");
35 }
36
37 void render(StringBuilder sbuf, IThrowableProxy tp) {
38 printFirstLine(sbuf, tp);
39
40 int commonFrames = tp.getCommonFrames();
41 StackTraceElementProxy[] stepArray = tp.getStackTraceElementProxyArray();
42
43 for (int i = 0; i < stepArray.length - commonFrames; i++) {
44 StackTraceElementProxy step = stepArray[i];
45 sbuf.append(TRACE_PREFIX);
46 sbuf.append(Transform.escapeTags(step.toString()));
47 sbuf.append(CoreConstants.LINE_SEPARATOR);
48 }
49
50 if (commonFrames > 0) {
51 sbuf.append(TRACE_PREFIX);
52 sbuf.append("\t... ").append(commonFrames).append(" common frames omitted")
53 .append(CoreConstants.LINE_SEPARATOR);
54 }
55 }
56
57 public void printFirstLine(StringBuilder sb, IThrowableProxy tp) {
58 int commonFrames = tp.getCommonFrames();
59 if (commonFrames > 0) {
60 sb.append("<br />").append(CoreConstants.CAUSED_BY);
61 }
62 sb.append(tp.getClassName()).append(": ").append(Transform.escapeTags(tp.getMessage()));
63 sb.append(CoreConstants.LINE_SEPARATOR);
64 }
65
66 }