comparison src/org/eclipse/jetty/util/log/JettyAwareLogger.java @ 802:3428c60d7cfc

replace jetty jars with source
author Franklin Schmidt <fschmidt@gmail.com>
date Wed, 07 Sep 2016 21:15:48 -0600
parents
children
comparison
equal deleted inserted replaced
801:6a21393191c1 802:3428c60d7cfc
1 //
2 // ========================================================================
3 // Copyright (c) 1995-2014 Mort Bay Consulting Pty. Ltd.
4 // ------------------------------------------------------------------------
5 // All rights reserved. This program and the accompanying materials
6 // are made available under the terms of the Eclipse Public License v1.0
7 // and Apache License v2.0 which accompanies this distribution.
8 //
9 // The Eclipse Public License is available at
10 // http://www.eclipse.org/legal/epl-v10.html
11 //
12 // The Apache License v2.0 is available at
13 // http://www.opensource.org/licenses/apache2.0.php
14 //
15 // You may elect to redistribute this code under either of these licenses.
16 // ========================================================================
17 //
18
19 package org.eclipse.jetty.util.log;
20
21 import org.slf4j.Marker;
22 import org.slf4j.helpers.FormattingTuple;
23 import org.slf4j.helpers.MessageFormatter;
24
25 /**
26 * JettyAwareLogger is used to fix a FQCN bug that arises from how Jetty
27 * Log uses an indirect slf4j implementation.
28 *
29 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=276670
30 */
31 class JettyAwareLogger implements org.slf4j.Logger
32 {
33 private static final int DEBUG = org.slf4j.spi.LocationAwareLogger.DEBUG_INT;
34 private static final int ERROR = org.slf4j.spi.LocationAwareLogger.ERROR_INT;
35 private static final int INFO = org.slf4j.spi.LocationAwareLogger.INFO_INT;
36 private static final int TRACE = org.slf4j.spi.LocationAwareLogger.TRACE_INT;
37 private static final int WARN = org.slf4j.spi.LocationAwareLogger.WARN_INT;
38
39 private static final String FQCN = Slf4jLog.class.getName();
40 private final org.slf4j.spi.LocationAwareLogger _logger;
41
42 public JettyAwareLogger(org.slf4j.spi.LocationAwareLogger logger)
43 {
44 _logger = logger;
45 }
46
47 /* ------------------------------------------------------------ */
48 /**
49 * @see org.slf4j.Logger#getName()
50 */
51 public String getName()
52 {
53 return _logger.getName();
54 }
55
56 /* ------------------------------------------------------------ */
57 /**
58 * @see org.slf4j.Logger#isTraceEnabled()
59 */
60 public boolean isTraceEnabled()
61 {
62 return _logger.isTraceEnabled();
63 }
64
65 /* ------------------------------------------------------------ */
66 /**
67 * @see org.slf4j.Logger#trace(java.lang.String)
68 */
69 public void trace(String msg)
70 {
71 log(null, TRACE, msg, null, null);
72 }
73
74 /* ------------------------------------------------------------ */
75 /**
76 * @see org.slf4j.Logger#trace(java.lang.String, java.lang.Object)
77 */
78 public void trace(String format, Object arg)
79 {
80 log(null, TRACE, format, new Object[]{arg}, null);
81 }
82
83 /* ------------------------------------------------------------ */
84 /**
85 * @see org.slf4j.Logger#trace(java.lang.String, java.lang.Object, java.lang.Object)
86 */
87 public void trace(String format, Object arg1, Object arg2)
88 {
89 log(null, TRACE, format, new Object[]{arg1,arg2}, null);
90 }
91
92 /* ------------------------------------------------------------ */
93 /**
94 * @see org.slf4j.Logger#trace(java.lang.String, java.lang.Object[])
95 */
96 public void trace(String format, Object[] argArray)
97 {
98 log(null, TRACE, format, argArray, null);
99 }
100
101 /* ------------------------------------------------------------ */
102 /**
103 * @see org.slf4j.Logger#trace(java.lang.String, java.lang.Throwable)
104 */
105 public void trace(String msg, Throwable t)
106 {
107 log(null, TRACE, msg, null, t);
108 }
109
110 /* ------------------------------------------------------------ */
111 /**
112 * @see org.slf4j.Logger#isTraceEnabled(org.slf4j.Marker)
113 */
114 public boolean isTraceEnabled(Marker marker)
115 {
116 return _logger.isTraceEnabled(marker);
117 }
118
119 /* ------------------------------------------------------------ */
120 /**
121 * @see org.slf4j.Logger#trace(org.slf4j.Marker, java.lang.String)
122 */
123 public void trace(Marker marker, String msg)
124 {
125 log(marker, TRACE, msg, null, null);
126 }
127
128 /* ------------------------------------------------------------ */
129 /**
130 * @see org.slf4j.Logger#trace(org.slf4j.Marker, java.lang.String, java.lang.Object)
131 */
132 public void trace(Marker marker, String format, Object arg)
133 {
134 log(marker, TRACE, format, new Object[]{arg}, null);
135 }
136
137 /* ------------------------------------------------------------ */
138 /**
139 * @see org.slf4j.Logger#trace(org.slf4j.Marker, java.lang.String, java.lang.Object, java.lang.Object)
140 */
141 public void trace(Marker marker, String format, Object arg1, Object arg2)
142 {
143 log(marker, TRACE, format, new Object[]{arg1,arg2}, null);
144 }
145
146 /* ------------------------------------------------------------ */
147 /**
148 * @see org.slf4j.Logger#trace(org.slf4j.Marker, java.lang.String, java.lang.Object[])
149 */
150 public void trace(Marker marker, String format, Object[] argArray)
151 {
152 log(marker, TRACE, format, argArray, null);
153 }
154
155 /* ------------------------------------------------------------ */
156 /**
157 * @see org.slf4j.Logger#trace(org.slf4j.Marker, java.lang.String, java.lang.Throwable)
158 */
159 public void trace(Marker marker, String msg, Throwable t)
160 {
161 log(marker, TRACE, msg, null, t);
162 }
163
164 /* ------------------------------------------------------------ */
165 /**
166 * @see org.slf4j.Logger#isDebugEnabled()
167 */
168 public boolean isDebugEnabled()
169 {
170 return _logger.isDebugEnabled();
171 }
172
173 /* ------------------------------------------------------------ */
174 /**
175 * @see org.slf4j.Logger#debug(java.lang.String)
176 */
177 public void debug(String msg)
178 {
179 log(null, DEBUG, msg, null, null);
180 }
181
182 /* ------------------------------------------------------------ */
183 /**
184 * @see org.slf4j.Logger#debug(java.lang.String, java.lang.Object)
185 */
186 public void debug(String format, Object arg)
187 {
188 log(null, DEBUG, format, new Object[]{arg}, null);
189 }
190
191 /* ------------------------------------------------------------ */
192 /**
193 * @see org.slf4j.Logger#debug(java.lang.String, java.lang.Object, java.lang.Object)
194 */
195 public void debug(String format, Object arg1, Object arg2)
196 {
197 log(null, DEBUG, format, new Object[]{arg1,arg2}, null);
198 }
199
200 /* ------------------------------------------------------------ */
201 /**
202 * @see org.slf4j.Logger#debug(java.lang.String, java.lang.Object[])
203 */
204 public void debug(String format, Object[] argArray)
205 {
206 log(null, DEBUG, format, argArray, null);
207 }
208
209 /* ------------------------------------------------------------ */
210 /**
211 * @see org.slf4j.Logger#debug(java.lang.String, java.lang.Throwable)
212 */
213 public void debug(String msg, Throwable t)
214 {
215 log(null, DEBUG, msg, null, t);
216 }
217
218 /* ------------------------------------------------------------ */
219 /**
220 * @see org.slf4j.Logger#isDebugEnabled(org.slf4j.Marker)
221 */
222 public boolean isDebugEnabled(Marker marker)
223 {
224 return _logger.isDebugEnabled(marker);
225 }
226
227 /* ------------------------------------------------------------ */
228 /**
229 * @see org.slf4j.Logger#debug(org.slf4j.Marker, java.lang.String)
230 */
231 public void debug(Marker marker, String msg)
232 {
233 log(marker, DEBUG, msg, null, null);
234 }
235
236 /* ------------------------------------------------------------ */
237 /**
238 * @see org.slf4j.Logger#debug(org.slf4j.Marker, java.lang.String, java.lang.Object)
239 */
240 public void debug(Marker marker, String format, Object arg)
241 {
242 log(marker, DEBUG, format, new Object[]{arg}, null);
243 }
244
245 /* ------------------------------------------------------------ */
246 /**
247 * @see org.slf4j.Logger#debug(org.slf4j.Marker, java.lang.String, java.lang.Object, java.lang.Object)
248 */
249 public void debug(Marker marker, String format, Object arg1, Object arg2)
250 {
251 log(marker, DEBUG, format, new Object[]{arg1,arg2}, null);
252 }
253
254 /* ------------------------------------------------------------ */
255 /**
256 * @see org.slf4j.Logger#debug(org.slf4j.Marker, java.lang.String, java.lang.Object[])
257 */
258 public void debug(Marker marker, String format, Object[] argArray)
259 {
260 log(marker, DEBUG, format, argArray, null);
261 }
262
263 /* ------------------------------------------------------------ */
264 /**
265 * @see org.slf4j.Logger#debug(org.slf4j.Marker, java.lang.String, java.lang.Throwable)
266 */
267 public void debug(Marker marker, String msg, Throwable t)
268 {
269 log(marker, DEBUG, msg, null, t);
270 }
271
272 /* ------------------------------------------------------------ */
273 /**
274 * @see org.slf4j.Logger#isInfoEnabled()
275 */
276 public boolean isInfoEnabled()
277 {
278 return _logger.isInfoEnabled();
279 }
280
281 /* ------------------------------------------------------------ */
282 /**
283 * @see org.slf4j.Logger#info(java.lang.String)
284 */
285 public void info(String msg)
286 {
287 log(null, INFO, msg, null, null);
288 }
289
290 /* ------------------------------------------------------------ */
291 /**
292 * @see org.slf4j.Logger#info(java.lang.String, java.lang.Object)
293 */
294 public void info(String format, Object arg)
295 {
296 log(null, INFO, format, new Object[]{arg}, null);
297 }
298
299 /* ------------------------------------------------------------ */
300 /**
301 * @see org.slf4j.Logger#info(java.lang.String, java.lang.Object, java.lang.Object)
302 */
303 public void info(String format, Object arg1, Object arg2)
304 {
305 log(null, INFO, format, new Object[]{arg1,arg2}, null);
306 }
307
308 /* ------------------------------------------------------------ */
309 /**
310 * @see org.slf4j.Logger#info(java.lang.String, java.lang.Object[])
311 */
312 public void info(String format, Object[] argArray)
313 {
314 log(null, INFO, format, argArray, null);
315 }
316
317 /* ------------------------------------------------------------ */
318 /**
319 * @see org.slf4j.Logger#info(java.lang.String, java.lang.Throwable)
320 */
321 public void info(String msg, Throwable t)
322 {
323 log(null, INFO, msg, null, t);
324 }
325
326 /* ------------------------------------------------------------ */
327 /**
328 * @see org.slf4j.Logger#isInfoEnabled(org.slf4j.Marker)
329 */
330 public boolean isInfoEnabled(Marker marker)
331 {
332 return _logger.isInfoEnabled(marker);
333 }
334
335 /* ------------------------------------------------------------ */
336 /**
337 * @see org.slf4j.Logger#info(org.slf4j.Marker, java.lang.String)
338 */
339 public void info(Marker marker, String msg)
340 {
341 log(marker, INFO, msg, null, null);
342 }
343
344 /* ------------------------------------------------------------ */
345 /**
346 * @see org.slf4j.Logger#info(org.slf4j.Marker, java.lang.String, java.lang.Object)
347 */
348 public void info(Marker marker, String format, Object arg)
349 {
350 log(marker, INFO, format, new Object[]{arg}, null);
351 }
352
353 /* ------------------------------------------------------------ */
354 /**
355 * @see org.slf4j.Logger#info(org.slf4j.Marker, java.lang.String, java.lang.Object, java.lang.Object)
356 */
357 public void info(Marker marker, String format, Object arg1, Object arg2)
358 {
359 log(marker, INFO, format, new Object[]{arg1,arg2}, null);
360 }
361
362 /* ------------------------------------------------------------ */
363 /**
364 * @see org.slf4j.Logger#info(org.slf4j.Marker, java.lang.String, java.lang.Object[])
365 */
366 public void info(Marker marker, String format, Object[] argArray)
367 {
368 log(marker, INFO, format, argArray, null);
369 }
370
371 /* ------------------------------------------------------------ */
372 /**
373 * @see org.slf4j.Logger#info(org.slf4j.Marker, java.lang.String, java.lang.Throwable)
374 */
375 public void info(Marker marker, String msg, Throwable t)
376 {
377 log(marker, INFO, msg, null, t);
378 }
379
380 /* ------------------------------------------------------------ */
381 /**
382 * @see org.slf4j.Logger#isWarnEnabled()
383 */
384 public boolean isWarnEnabled()
385 {
386 return _logger.isWarnEnabled();
387 }
388
389 /* ------------------------------------------------------------ */
390 /**
391 * @see org.slf4j.Logger#warn(java.lang.String)
392 */
393 public void warn(String msg)
394 {
395 log(null, WARN, msg, null, null);
396 }
397
398 /* ------------------------------------------------------------ */
399 /**
400 * @see org.slf4j.Logger#warn(java.lang.String, java.lang.Object)
401 */
402 public void warn(String format, Object arg)
403 {
404 log(null, WARN, format, new Object[]{arg}, null);
405 }
406
407 /* ------------------------------------------------------------ */
408 /**
409 * @see org.slf4j.Logger#warn(java.lang.String, java.lang.Object[])
410 */
411 public void warn(String format, Object[] argArray)
412 {
413 log(null, WARN, format, argArray, null);
414 }
415
416 /* ------------------------------------------------------------ */
417 /**
418 * @see org.slf4j.Logger#warn(java.lang.String, java.lang.Object, java.lang.Object)
419 */
420 public void warn(String format, Object arg1, Object arg2)
421 {
422 log(null, WARN, format, new Object[]{arg1,arg2}, null);
423 }
424
425 /* ------------------------------------------------------------ */
426 /**
427 * @see org.slf4j.Logger#warn(java.lang.String, java.lang.Throwable)
428 */
429 public void warn(String msg, Throwable t)
430 {
431 log(null, WARN, msg, null, t);
432 }
433
434 /* ------------------------------------------------------------ */
435 /**
436 * @see org.slf4j.Logger#isWarnEnabled(org.slf4j.Marker)
437 */
438 public boolean isWarnEnabled(Marker marker)
439 {
440 return _logger.isWarnEnabled(marker);
441 }
442
443 /* ------------------------------------------------------------ */
444 /**
445 * @see org.slf4j.Logger#warn(org.slf4j.Marker, java.lang.String)
446 */
447 public void warn(Marker marker, String msg)
448 {
449 log(marker, WARN, msg, null, null);
450 }
451
452 /* ------------------------------------------------------------ */
453 /**
454 * @see org.slf4j.Logger#warn(org.slf4j.Marker, java.lang.String, java.lang.Object)
455 */
456 public void warn(Marker marker, String format, Object arg)
457 {
458 log(marker, WARN, format, new Object[]{arg}, null);
459 }
460
461 /* ------------------------------------------------------------ */
462 /**
463 * @see org.slf4j.Logger#warn(org.slf4j.Marker, java.lang.String, java.lang.Object, java.lang.Object)
464 */
465 public void warn(Marker marker, String format, Object arg1, Object arg2)
466 {
467 log(marker, WARN, format, new Object[]{arg1,arg2}, null);
468 }
469
470 /* ------------------------------------------------------------ */
471 /**
472 * @see org.slf4j.Logger#warn(org.slf4j.Marker, java.lang.String, java.lang.Object[])
473 */
474 public void warn(Marker marker, String format, Object[] argArray)
475 {
476 log(marker, WARN, format, argArray, null);
477 }
478
479 /* ------------------------------------------------------------ */
480 /**
481 * @see org.slf4j.Logger#warn(org.slf4j.Marker, java.lang.String, java.lang.Throwable)
482 */
483 public void warn(Marker marker, String msg, Throwable t)
484 {
485 log(marker, WARN, msg, null, t);
486 }
487
488 /* ------------------------------------------------------------ */
489 /**
490 * @see org.slf4j.Logger#isErrorEnabled()
491 */
492 public boolean isErrorEnabled()
493 {
494 return _logger.isErrorEnabled();
495 }
496
497 /* ------------------------------------------------------------ */
498 /**
499 * @see org.slf4j.Logger#error(java.lang.String)
500 */
501 public void error(String msg)
502 {
503 log(null, ERROR, msg, null, null);
504 }
505
506 /* ------------------------------------------------------------ */
507 /**
508 * @see org.slf4j.Logger#error(java.lang.String, java.lang.Object)
509 */
510 public void error(String format, Object arg)
511 {
512 log(null, ERROR, format, new Object[]{arg}, null);
513 }
514
515 /* ------------------------------------------------------------ */
516 /**
517 * @see org.slf4j.Logger#error(java.lang.String, java.lang.Object, java.lang.Object)
518 */
519 public void error(String format, Object arg1, Object arg2)
520 {
521 log(null, ERROR, format, new Object[]{arg1,arg2}, null);
522 }
523
524 /* ------------------------------------------------------------ */
525 /**
526 * @see org.slf4j.Logger#error(java.lang.String, java.lang.Object[])
527 */
528 public void error(String format, Object[] argArray)
529 {
530 log(null, ERROR, format, argArray, null);
531 }
532
533 /* ------------------------------------------------------------ */
534 /**
535 * @see org.slf4j.Logger#error(java.lang.String, java.lang.Throwable)
536 */
537 public void error(String msg, Throwable t)
538 {
539 log(null, ERROR, msg, null, t);
540 }
541
542 /* ------------------------------------------------------------ */
543 /**
544 * @see org.slf4j.Logger#isErrorEnabled(org.slf4j.Marker)
545 */
546 public boolean isErrorEnabled(Marker marker)
547 {
548 return _logger.isErrorEnabled(marker);
549 }
550
551 /* ------------------------------------------------------------ */
552 /**
553 * @see org.slf4j.Logger#error(org.slf4j.Marker, java.lang.String)
554 */
555 public void error(Marker marker, String msg)
556 {
557 log(marker, ERROR, msg, null, null);
558 }
559
560 /* ------------------------------------------------------------ */
561 /**
562 * @see org.slf4j.Logger#error(org.slf4j.Marker, java.lang.String, java.lang.Object)
563 */
564 public void error(Marker marker, String format, Object arg)
565 {
566 log(marker, ERROR, format, new Object[]{arg}, null);
567 }
568
569 /* ------------------------------------------------------------ */
570 /**
571 * @see org.slf4j.Logger#error(org.slf4j.Marker, java.lang.String, java.lang.Object, java.lang.Object)
572 */
573 public void error(Marker marker, String format, Object arg1, Object arg2)
574 {
575 log(marker, ERROR, format, new Object[]{arg1,arg2}, null);
576 }
577
578 /* ------------------------------------------------------------ */
579 /**
580 * @see org.slf4j.Logger#error(org.slf4j.Marker, java.lang.String, java.lang.Object[])
581 */
582 public void error(Marker marker, String format, Object[] argArray)
583 {
584 log(marker, ERROR, format, argArray, null);
585 }
586
587 /* ------------------------------------------------------------ */
588 /**
589 * @see org.slf4j.Logger#error(org.slf4j.Marker, java.lang.String, java.lang.Throwable)
590 */
591 public void error(Marker marker, String msg, Throwable t)
592 {
593 log(marker, ERROR, msg, null, t);
594 }
595
596 @Override
597 public String toString()
598 {
599 return _logger.toString();
600 }
601
602 private void log(Marker marker, int level, String msg, Object[] argArray, Throwable t)
603 {
604 if (argArray == null)
605 {
606 // Simple SLF4J Message (no args)
607 _logger.log(marker, FQCN, level, msg, null, t);
608 }
609 else
610 {
611 int loggerLevel = _logger.isTraceEnabled() ? TRACE :
612 _logger.isDebugEnabled() ? DEBUG :
613 _logger.isInfoEnabled() ? INFO :
614 _logger.isWarnEnabled() ? WARN : ERROR;
615 if (loggerLevel <= level)
616 {
617 // Don't assume downstream handles argArray properly.
618 // Do it the SLF4J way here to eliminate that as a bug.
619 FormattingTuple ft = MessageFormatter.arrayFormat(msg, argArray);
620 _logger.log(marker, FQCN, level, ft.getMessage(), null, t);
621 }
622 }
623 }
624 }