1 package ch.qos.logback.classic.pattern;
2
3 import ch.qos.logback.classic.spi.LoggingEvent;
4 import ch.qos.logback.core.pattern.Converter;
5 import ch.qos.logback.core.pattern.ConverterUtil;
6 import ch.qos.logback.core.pattern.PostCompileProcessor;
7
8 public class EnsureExceptionHandling implements
9 PostCompileProcessor<LoggingEvent> {
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26 public void process(Converter<LoggingEvent> head) {
27 if (!chainHandlesThrowable(head)) {
28 Converter<LoggingEvent> tail = ConverterUtil.findTail(head);
29 Converter<LoggingEvent> exConverter = new ExtendedThrowableProxyConverter();
30 if (tail == null) {
31 head = exConverter;
32 } else {
33 tail.setNext(exConverter);
34 }
35 }
36 }
37
38
39
40
41
42
43
44
45
46 public boolean chainHandlesThrowable(Converter head) {
47 Converter c = head;
48 while (c != null) {
49 if (c instanceof ThrowableHandlingConverter) {
50 return true;
51 }
52 c = c.getNext();
53 }
54 return false;
55 }
56 }