1
2
3
4
5
6
7
8
9
10
11 package org.eclipse.jgit.junit.http;
12
13 import java.text.MessageFormat;
14 import java.util.ArrayList;
15 import java.util.Collections;
16 import java.util.List;
17
18 import org.eclipse.jetty.util.log.Logger;
19
20
21
22
23 public class RecordingLogger implements Logger {
24 private static List<Warning> warnings = new ArrayList<>();
25
26
27
28
29
30 public static void clear() {
31 synchronized (warnings) {
32 warnings.clear();
33 }
34 }
35
36
37
38
39
40
41 public static List<Warning> getWarnings() {
42 synchronized (warnings) {
43 ArrayList<Warning> copy = new ArrayList<>(warnings);
44 return Collections.unmodifiableList(copy);
45 }
46 }
47
48 @SuppressWarnings("serial")
49 public static class Warning extends Exception {
50 public Warning(String msg) {
51 super(msg);
52 }
53
54 public Warning(String msg, Throwable cause) {
55 super(msg, cause);
56 }
57
58 public Warning(Throwable thrown) {
59 super(thrown);
60 }
61 }
62
63 private final String name;
64
65
66
67
68 public RecordingLogger() {
69 this("");
70 }
71
72
73
74
75
76
77 public RecordingLogger(String name) {
78 this.name = name;
79 }
80
81
82 @Override
83 public Logger getLogger(@SuppressWarnings("hiding") String name) {
84 return new RecordingLogger(name);
85 }
86
87
88 @Override
89 public String getName() {
90 return name;
91 }
92
93
94
95
96
97
98
99
100 public void warn(String msg, Object arg0, Object arg1) {
101 synchronized (warnings) {
102 warnings.add(new Warning(MessageFormat.format(msg, arg0, arg1)));
103 }
104 }
105
106
107 @Override
108 public void warn(String msg, Throwable th) {
109 synchronized (warnings) {
110 warnings.add(new Warning(msg, th));
111 }
112 }
113
114
115
116
117
118
119
120 public void warn(String msg) {
121 synchronized (warnings) {
122 warnings.add(new Warning(msg));
123 }
124 }
125
126
127
128
129
130
131
132
133 public void debug(String msg, Object arg0, Object arg1) {
134
135 }
136
137
138 @Override
139 public void debug(String msg, Throwable th) {
140
141 }
142
143
144
145
146
147
148
149 public void debug(String msg) {
150
151 }
152
153
154
155
156
157
158
159
160 public void info(String msg, Object arg0, Object arg1) {
161
162 }
163
164
165
166
167
168
169 public void info(String msg) {
170
171 }
172
173
174 @Override
175 public boolean isDebugEnabled() {
176 return false;
177 }
178
179
180 @Override
181 public void setDebugEnabled(boolean enabled) {
182
183 }
184
185
186 @Override
187 public void warn(String msg, Object... args) {
188 synchronized (warnings) {
189 int i = 0;
190 int index = msg.indexOf("{}");
191 while (index >= 0) {
192 msg = msg.replaceFirst("\\{\\}", "{" + i++ + "}");
193 index = msg.indexOf("{}");
194 }
195 warnings.add(new Warning(MessageFormat.format(msg, args)));
196 }
197 }
198
199
200 @Override
201 public void warn(Throwable thrown) {
202 synchronized (warnings) {
203 warnings.add(new Warning(thrown));
204 }
205 }
206
207
208 @Override
209 public void info(String msg, Object... args) {
210
211 }
212
213
214 @Override
215 public void info(Throwable thrown) {
216
217 }
218
219
220 @Override
221 public void info(String msg, Throwable thrown) {
222
223 }
224
225
226 @Override
227 public void debug(String msg, Object... args) {
228
229 }
230
231
232 @Override
233 public void debug(Throwable thrown) {
234
235 }
236
237
238 @Override
239 public void ignore(Throwable arg0) {
240
241 }
242
243
244 @Override
245 public void debug(String msg, long value) {
246
247 }
248 }