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