1
2
3
4
5
6
7
8
9
10
11
12
13
14 package ch.qos.logback.access.common.html;
15
16 import static ch.qos.logback.core.CoreConstants.LINE_SEPARATOR;
17
18 import java.util.Map;
19 import java.util.function.Supplier;
20
21 import ch.qos.logback.access.common.PatternLayout;
22 import ch.qos.logback.access.common.spi.IAccessEvent;
23 import ch.qos.logback.core.html.HTMLLayoutBase;
24 import ch.qos.logback.core.pattern.Converter;
25 import ch.qos.logback.core.pattern.DynamicConverter;
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42 public class HTMLLayout extends HTMLLayoutBase<IAccessEvent> {
43
44
45
46
47 static final String DEFAULT_CONVERSION_PATTERN = "%h%l%u%t%r%s%b";
48
49
50
51
52
53 public HTMLLayout() {
54 pattern = DEFAULT_CONVERSION_PATTERN;
55 cssBuilder = new DefaultCssBuilder();
56 }
57
58 @Override
59 protected Map<String, Supplier<DynamicConverter>> getDefaultConverterSupplierMap() {
60 return PatternLayout.ACCESS_DEFAULT_CONVERTER_SUPPLIER_MAP;
61 }
62
63 @Override
64 public String doLayout(IAccessEvent event) {
65 StringBuilder buf = new StringBuilder();
66 startNewTableIfLimitReached(buf);
67
68 boolean odd = true;
69 if (((counter++) & 1) == 0) {
70 odd = false;
71 }
72
73 buf.append(LINE_SEPARATOR);
74 buf.append("<tr class=\"");
75 if (odd) {
76 buf.append(" odd\">");
77 } else {
78 buf.append(" even\">");
79 }
80 buf.append(LINE_SEPARATOR);
81
82 Converter<IAccessEvent> c = head;
83 while (c != null) {
84 appendEventToBuffer(buf, c, event);
85 c = c.getNext();
86 }
87 buf.append("</tr>");
88 buf.append(LINE_SEPARATOR);
89
90 return buf.toString();
91 }
92
93 private void appendEventToBuffer(StringBuilder buf, Converter<IAccessEvent> c, IAccessEvent event) {
94 buf.append("<td class=\"");
95 buf.append(computeConverterName(c));
96 buf.append("\">");
97 c.write(buf, event);
98 buf.append("</td>");
99 buf.append(LINE_SEPARATOR);
100 }
101 }