1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
|
20 | |
|
21 | |
|
22 | |
|
23 | |
|
24 | |
|
25 | |
|
26 | |
|
27 | |
|
28 | |
|
29 | |
|
30 | |
package org.slf4j.impl; |
31 | |
|
32 | |
import lombok.EqualsAndHashCode; |
33 | |
import lombok.ToString; |
34 | |
import org.apache.maven.plugin.logging.Log; |
35 | |
import org.slf4j.helpers.FormattingTuple; |
36 | |
import org.slf4j.helpers.MarkerIgnoringBase; |
37 | |
import org.slf4j.helpers.MessageFormatter; |
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | |
|
43 | |
|
44 | |
|
45 | |
|
46 | |
|
47 | |
|
48 | |
|
49 | |
|
50 | |
|
51 | |
|
52 | |
|
53 | |
|
54 | 0 | @ToString |
55 | 0 | @EqualsAndHashCode(callSuper = false) |
56 | |
@SuppressWarnings("PMD.TooManyMethods") |
57 | |
final class Slf4jAdapter extends MarkerIgnoringBase { |
58 | |
|
59 | |
|
60 | |
|
61 | |
|
62 | |
public static final long serialVersionUID = 0x12C0976798AB5439L; |
63 | |
|
64 | |
|
65 | |
|
66 | |
|
67 | |
private final transient Log mlog; |
68 | |
|
69 | |
|
70 | |
|
71 | |
|
72 | |
private final transient String label; |
73 | |
|
74 | |
|
75 | |
|
76 | |
|
77 | |
|
78 | |
|
79 | |
public Slf4jAdapter(final Log log, final String name) { |
80 | 3 | super(); |
81 | 3 | this.mlog = log; |
82 | 3 | this.label = name; |
83 | 3 | } |
84 | |
|
85 | |
|
86 | |
|
87 | |
|
88 | |
@Override |
89 | |
public String getName() { |
90 | 1 | return this.getClass().getName(); |
91 | |
} |
92 | |
|
93 | |
|
94 | |
|
95 | |
|
96 | |
@Override |
97 | |
public boolean isTraceEnabled() { |
98 | 1 | return false; |
99 | |
} |
100 | |
|
101 | |
|
102 | |
|
103 | |
|
104 | |
@Override |
105 | |
public void trace(final String msg) { |
106 | 1 | this.mlog.debug(this.decorate(msg)); |
107 | 1 | } |
108 | |
|
109 | |
|
110 | |
|
111 | |
|
112 | |
@Override |
113 | |
public void trace(final String format, final Object arg) { |
114 | 1 | this.mlog.debug(this.decorate(this.format(format, arg))); |
115 | 1 | } |
116 | |
|
117 | |
|
118 | |
|
119 | |
|
120 | |
@Override |
121 | |
public void trace(final String format, final Object first, |
122 | |
final Object second) { |
123 | 2 | this.mlog.debug(this.decorate(this.format(format, first, second))); |
124 | 2 | } |
125 | |
|
126 | |
|
127 | |
|
128 | |
|
129 | |
@Override |
130 | |
public void trace(final String format, final Object... array) { |
131 | 0 | this.mlog.debug(this.decorate(this.format(format, array))); |
132 | 0 | } |
133 | |
|
134 | |
|
135 | |
|
136 | |
|
137 | |
@Override |
138 | |
public void trace(final String msg, final Throwable thr) { |
139 | 1 | this.mlog.debug(this.decorate(msg), thr); |
140 | 1 | } |
141 | |
|
142 | |
|
143 | |
|
144 | |
|
145 | |
@Override |
146 | |
public boolean isDebugEnabled() { |
147 | 1 | return this.mlog.isDebugEnabled(); |
148 | |
} |
149 | |
|
150 | |
|
151 | |
|
152 | |
|
153 | |
@Override |
154 | |
public void debug(final String msg) { |
155 | 1 | this.mlog.debug(this.decorate(msg)); |
156 | 1 | } |
157 | |
|
158 | |
|
159 | |
|
160 | |
|
161 | |
@Override |
162 | |
public void debug(final String format, final Object arg) { |
163 | 1 | this.mlog.debug(this.decorate(this.format(format, arg))); |
164 | 1 | } |
165 | |
|
166 | |
|
167 | |
|
168 | |
|
169 | |
@Override |
170 | |
public void debug(final String format, final Object first, |
171 | |
final Object second) { |
172 | 2 | this.mlog.debug(this.decorate(this.format(format, first, second))); |
173 | 2 | } |
174 | |
|
175 | |
|
176 | |
|
177 | |
|
178 | |
@Override |
179 | |
public void debug(final String format, final Object... array) { |
180 | 0 | this.mlog.debug(this.decorate(this.format(format, array))); |
181 | 0 | } |
182 | |
|
183 | |
|
184 | |
|
185 | |
|
186 | |
@Override |
187 | |
public void debug(final String msg, final Throwable thr) { |
188 | 1 | this.mlog.debug(this.decorate(msg), thr); |
189 | 1 | } |
190 | |
|
191 | |
|
192 | |
|
193 | |
|
194 | |
@Override |
195 | |
public boolean isInfoEnabled() { |
196 | 1 | return true; |
197 | |
} |
198 | |
|
199 | |
|
200 | |
|
201 | |
|
202 | |
@Override |
203 | |
public void info(final String msg) { |
204 | 2 | this.mlog.info(msg); |
205 | 2 | } |
206 | |
|
207 | |
|
208 | |
|
209 | |
|
210 | |
@Override |
211 | |
public void info(final String format, final Object arg) { |
212 | 1 | this.mlog.info(this.format(format, arg)); |
213 | 1 | } |
214 | |
|
215 | |
|
216 | |
|
217 | |
|
218 | |
@Override |
219 | |
public void info(final String format, final Object first, |
220 | |
final Object second) { |
221 | 2 | this.mlog.info(this.format(format, first, second)); |
222 | 2 | } |
223 | |
|
224 | |
|
225 | |
|
226 | |
|
227 | |
@Override |
228 | |
public void info(final String format, final Object... array) { |
229 | 0 | this.mlog.info(this.format(format, array)); |
230 | 0 | } |
231 | |
|
232 | |
|
233 | |
|
234 | |
|
235 | |
@Override |
236 | |
public void info(final String msg, final Throwable thr) { |
237 | 1 | this.mlog.info(msg, thr); |
238 | 1 | } |
239 | |
|
240 | |
|
241 | |
|
242 | |
|
243 | |
@Override |
244 | |
public boolean isWarnEnabled() { |
245 | 1 | return true; |
246 | |
} |
247 | |
|
248 | |
|
249 | |
|
250 | |
|
251 | |
@Override |
252 | |
public void warn(final String msg) { |
253 | 1 | this.mlog.warn(msg); |
254 | 1 | } |
255 | |
|
256 | |
|
257 | |
|
258 | |
|
259 | |
@Override |
260 | |
public void warn(final String format, final Object arg) { |
261 | 1 | this.mlog.warn(this.format(format, arg)); |
262 | 1 | } |
263 | |
|
264 | |
|
265 | |
|
266 | |
|
267 | |
@Override |
268 | |
public void warn(final String format, final Object... array) { |
269 | 0 | this.mlog.warn(this.format(format, array)); |
270 | 0 | } |
271 | |
|
272 | |
|
273 | |
|
274 | |
|
275 | |
@Override |
276 | |
public void warn(final String format, final Object first, |
277 | |
final Object second) { |
278 | 2 | this.mlog.warn(this.format(format, first, second)); |
279 | 2 | } |
280 | |
|
281 | |
|
282 | |
|
283 | |
|
284 | |
@Override |
285 | |
public void warn(final String msg, final Throwable thr) { |
286 | 1 | this.mlog.warn(msg, thr); |
287 | 1 | } |
288 | |
|
289 | |
|
290 | |
|
291 | |
|
292 | |
@Override |
293 | |
public boolean isErrorEnabled() { |
294 | 1 | return true; |
295 | |
} |
296 | |
|
297 | |
|
298 | |
|
299 | |
|
300 | |
@Override |
301 | |
public void error(final String msg) { |
302 | 1 | this.mlog.error(msg); |
303 | 1 | } |
304 | |
|
305 | |
|
306 | |
|
307 | |
|
308 | |
@Override |
309 | |
public void error(final String format, final Object arg) { |
310 | 1 | this.mlog.error(this.format(format, arg)); |
311 | 1 | } |
312 | |
|
313 | |
|
314 | |
|
315 | |
|
316 | |
@Override |
317 | |
public void error(final String format, final Object first, |
318 | |
final Object second) { |
319 | 2 | this.mlog.error(this.format(format, first, second)); |
320 | 2 | } |
321 | |
|
322 | |
|
323 | |
|
324 | |
|
325 | |
@Override |
326 | |
public void error(final String format, final Object... array) { |
327 | 0 | this.mlog.error(this.format(format, array)); |
328 | 0 | } |
329 | |
|
330 | |
|
331 | |
|
332 | |
|
333 | |
@Override |
334 | |
public void error(final String msg, final Throwable thr) { |
335 | 1 | this.mlog.error(msg, thr); |
336 | 1 | } |
337 | |
|
338 | |
|
339 | |
|
340 | |
|
341 | |
|
342 | |
|
343 | |
|
344 | |
private String format(final String format, final Object arg) { |
345 | 5 | final FormattingTuple tuple = |
346 | |
MessageFormatter.format(format, arg); |
347 | 5 | return tuple.getMessage(); |
348 | |
} |
349 | |
|
350 | |
|
351 | |
|
352 | |
|
353 | |
|
354 | |
|
355 | |
|
356 | |
|
357 | |
private String format(final String format, final Object first, |
358 | |
final Object second) { |
359 | 10 | final FormattingTuple tuple = |
360 | |
MessageFormatter.format(format, first, second); |
361 | 10 | return tuple.getMessage(); |
362 | |
} |
363 | |
|
364 | |
|
365 | |
|
366 | |
|
367 | |
|
368 | |
|
369 | |
|
370 | |
private String format(final String format, final Object[] array) { |
371 | 0 | final FormattingTuple tuple = |
372 | |
MessageFormatter.format(format, array); |
373 | 0 | return tuple.getMessage(); |
374 | |
} |
375 | |
|
376 | |
|
377 | |
|
378 | |
|
379 | |
|
380 | |
|
381 | |
private String decorate(final String msg) { |
382 | 10 | return String.format( |
383 | |
"%s %s: %s", |
384 | |
Thread.currentThread().getName(), |
385 | |
this.label, |
386 | |
msg |
387 | |
); |
388 | |
} |
389 | |
|
390 | |
} |