1 /**
2 * Copyright (c) 2004-2011 QOS.ch
3 * All rights reserved.
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining
6 * a copy of this software and associated documentation files (the
7 * "Software"), to deal in the Software without restriction, including
8 * without limitation the rights to use, copy, modify, merge, publish,
9 * distribute, sublicense, and/or sell copies of the Software, and to
10 * permit persons to whom the Software is furnished to do so, subject to
11 * the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be
14 * included in all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 *
24 */
25
26 package org.slf4j.impl;
27
28 import org.apache.commons.logging.Log;
29 import org.slf4j.Logger;
30 import org.slf4j.helpers.FormattingTuple;
31 import org.slf4j.helpers.MarkerIgnoringBase;
32 import org.slf4j.helpers.MessageFormatter;
33
34 /**
35 * A wrapper over {@link org.apache.commons.logging.Log
36 * org.apache.commons.logging.Log} in conformance with the {@link Logger}
37 * interface.
38 *
39 * @author Ceki Gülcü
40 */
41 public final class JCLLoggerAdapter extends MarkerIgnoringBase {
42
43 private static final long serialVersionUID = 4141593417490482209L;
44 final Log log;
45
46 // WARN: JCLLoggerAdapter constructor should have only package access so
47 // that only JCLLoggerFactory be able to create one.
48 JCLLoggerAdapter(Log log, String name) {
49 this.log = log;
50 this.name = name;
51 }
52
53 /**
54 * Delegates to the {@link Log#isTraceEnabled} method of the underlying
55 * {@link Log} instance.
56 */
57 public boolean isTraceEnabled() {
58 return log.isTraceEnabled();
59 }
60
61 //
62
63 /**
64 * Delegates to the {@link Log#trace(java.lang.Object)} method of the underlying
65 * {@link Log} instance.
66 *
67 * @param msg - the message object to be logged
68 */
69 public void trace(String msg) {
70 log.trace(msg);
71 }
72
73 /**
74 * Delegates to the {@link Log#trace(java.lang.Object)} method of the underlying
75 * {@link Log} instance.
76 *
77 * <p>
78 * However, this form avoids superfluous object creation when the logger is disabled
79 * for level TRACE.
80 * </p>
81 *
82 * @param format
83 * the format string
84 * @param arg
85 * the argument
86 */
87 public void trace(String format, Object arg) {
88 if (log.isTraceEnabled()) {
89 FormattingTuple ft = MessageFormatter.format(format, arg);
90 log.trace(ft.getMessage(), ft.getThrowable());
91 }
92 }
93
94 /**
95 * Delegates to the {@link Log#trace(java.lang.Object)} method of the underlying
96 * {@link Log} instance.
97 *
98 * <p>
99 * However, this form avoids superfluous object creation when the logger is disabled
100 * for level TRACE.
101 * </p>
102 *
103 * @param format
104 * the format string
105 * @param arg1
106 * the first argument
107 * @param arg2
108 * the second argument
109 */
110 public void trace(String format, Object arg1, Object arg2) {
111 if (log.isTraceEnabled()) {
112 FormattingTuple ft = MessageFormatter.format(format, arg1, arg2);
113 log.trace(ft.getMessage(), ft.getThrowable());
114 }
115 }
116
117 /**
118 * Delegates to the {@link Log#trace(java.lang.Object)} method of the underlying
119 * {@link Log} instance.
120 *
121 * <p>
122 * However, this form avoids superfluous object creation when the logger is disabled
123 * for level TRACE.
124 * </p>
125 *
126 * @param format the format string
127 * @param arguments a list of 3 or more arguments
128 */
129 public void trace(String format, Object... arguments) {
130 if (log.isTraceEnabled()) {
131 FormattingTuple ft = MessageFormatter.arrayFormat(format, arguments);
132 log.trace(ft.getMessage(), ft.getThrowable());
133 }
134 }
135
136 /**
137 * Delegates to the {@link Log#trace(java.lang.Object, java.lang.Throwable)} method of
138 * the underlying {@link Log} instance.
139 *
140 * @param msg
141 * the message accompanying the exception
142 * @param t
143 * the exception (throwable) to log
144 */
145 public void trace(String msg, Throwable t) {
146 log.trace(msg, t);
147 }
148
149 /**
150 * Delegates to the {@link Log#isDebugEnabled} method of the underlying
151 * {@link Log} instance.
152 */
153 public boolean isDebugEnabled() {
154 return log.isDebugEnabled();
155 }
156
157 //
158
159 /**
160 * Delegates to the {@link Log#debug(java.lang.Object)} method of the underlying
161 * {@link Log} instance.
162 *
163 * @param msg - the message object to be logged
164 */
165 public void debug(String msg) {
166 log.debug(msg);
167 }
168
169 /**
170 * Delegates to the {@link Log#debug(java.lang.Object)} method of the underlying
171 * {@link Log} instance.
172 *
173 * <p>
174 * However, this form avoids superfluous object creation when the logger is disabled
175 * for level DEBUG.
176 * </p>
177 *
178 * @param format
179 * the format string
180 * @param arg
181 * the argument
182 */
183 public void debug(String format, Object arg) {
184 if (log.isDebugEnabled()) {
185 FormattingTuple ft = MessageFormatter.format(format, arg);
186 log.debug(ft.getMessage(), ft.getThrowable());
187 }
188 }
189
190 /**
191 * Delegates to the {@link Log#debug(java.lang.Object)} method of the underlying
192 * {@link Log} instance.
193 *
194 * <p>
195 * However, this form avoids superfluous object creation when the logger is disabled
196 * for level DEBUG.
197 * </p>
198 *
199 * @param format
200 * the format string
201 * @param arg1
202 * the first argument
203 * @param arg2
204 * the second argument
205 */
206 public void debug(String format, Object arg1, Object arg2) {
207 if (log.isDebugEnabled()) {
208 FormattingTuple ft = MessageFormatter.format(format, arg1, arg2);
209 log.debug(ft.getMessage(), ft.getThrowable());
210 }
211 }
212
213 /**
214 * Delegates to the {@link Log#debug(java.lang.Object)} method of the underlying
215 * {@link Log} instance.
216 *
217 * <p>
218 * However, this form avoids superfluous object creation when the logger is disabled
219 * for level DEBUG.
220 * </p>
221 *
222 * @param format the format string
223 * @param arguments a list of 3 or more arguments
224 */
225 public void debug(String format, Object... arguments) {
226 if (log.isDebugEnabled()) {
227 FormattingTuple ft = MessageFormatter.arrayFormat(format, arguments);
228 log.debug(ft.getMessage(), ft.getThrowable());
229 }
230 }
231
232 /**
233 * Delegates to the {@link Log#debug(java.lang.Object, java.lang.Throwable)} method of
234 * the underlying {@link Log} instance.
235 *
236 * @param msg
237 * the message accompanying the exception
238 * @param t
239 * the exception (throwable) to log
240 */
241 public void debug(String msg, Throwable t) {
242 log.debug(msg, t);
243 }
244
245 /**
246 * Delegates to the {@link Log#isInfoEnabled} method of the underlying
247 * {@link Log} instance.
248 */
249 public boolean isInfoEnabled() {
250 return log.isInfoEnabled();
251 }
252
253 /**
254 * Delegates to the {@link Log#debug(java.lang.Object)} method of the underlying
255 * {@link Log} instance.
256 *
257 * @param msg - the message object to be logged
258 */
259 public void info(String msg) {
260 log.info(msg);
261 }
262
263 /**
264 * Delegates to the {@link Log#info(java.lang.Object)} method of the underlying
265 * {@link Log} instance.
266 *
267 * <p>
268 * However, this form avoids superfluous object creation when the logger is disabled
269 * for level INFO.
270 * </p>
271 *
272 * @param format
273 * the format string
274 * @param arg
275 * the argument
276 */
277
278 public void info(String format, Object arg) {
279 if (log.isInfoEnabled()) {
280 FormattingTuple ft = MessageFormatter.format(format, arg);
281 log.info(ft.getMessage(), ft.getThrowable());
282 }
283 }
284
285 /**
286 * Delegates to the {@link Log#info(java.lang.Object)} method of the underlying
287 * {@link Log} instance.
288 *
289 * <p>
290 * However, this form avoids superfluous object creation when the logger is disabled
291 * for level INFO.
292 * </p>
293 *
294 * @param format
295 * the format string
296 * @param arg1
297 * the first argument
298 * @param arg2
299 * the second argument
300 */
301 public void info(String format, Object arg1, Object arg2) {
302 if (log.isInfoEnabled()) {
303
304 FormattingTuple ft = MessageFormatter.format(format, arg1, arg2);
305 log.info(ft.getMessage(), ft.getThrowable());
306 }
307 }
308
309 /**
310 * Delegates to the {@link Log#info(java.lang.Object)} method of the underlying
311 * {@link Log} instance.
312 *
313 * <p>
314 * However, this form avoids superfluous object creation when the logger is disabled
315 * for level INFO.
316 * </p>
317 *
318 * @param format the format string
319 * @param arguments a list of 3 or more arguments
320 */
321 public void info(String format, Object... arguments) {
322 if (log.isInfoEnabled()) {
323 FormattingTuple ft = MessageFormatter.arrayFormat(format, arguments);
324 log.info(ft.getMessage(), ft.getThrowable());
325 }
326 }
327
328 /**
329 * Delegates to the {@link Log#info(java.lang.Object, java.lang.Throwable)} method of
330 * the underlying {@link Log} instance.
331 *
332 * @param msg
333 * the message accompanying the exception
334 * @param t
335 * the exception (throwable) to log
336 */
337 public void info(String msg, Throwable t) {
338 log.info(msg, t);
339 }
340
341 /**
342 * Delegates to the {@link Log#isWarnEnabled} method of the underlying
343 * {@link Log} instance.
344 */
345 public boolean isWarnEnabled() {
346 return log.isWarnEnabled();
347 }
348
349 /**
350 * Delegates to the {@link Log#warn(java.lang.Object)} method of the underlying
351 * {@link Log} instance.
352 *
353 * @param msg - the message object to be logged
354 */
355 public void warn(String msg) {
356 log.warn(msg);
357 }
358
359 /**
360 * Delegates to the {@link Log#warn(java.lang.Object)} method of the underlying
361 * {@link Log} instance.
362 *
363 * <p>
364 * However, this form avoids superfluous object creation when the logger is disabled
365 * for level WARN.
366 * </p>
367 *
368 * @param format
369 * the format string
370 * @param arg
371 * the argument
372 */
373 public void warn(String format, Object arg) {
374 if (log.isWarnEnabled()) {
375 FormattingTuple ft = MessageFormatter.format(format, arg);
376 log.warn(ft.getMessage(), ft.getThrowable());
377 }
378 }
379
380 /**
381 * Delegates to the {@link Log#warn(java.lang.Object)} method of the underlying
382 * {@link Log} instance.
383 *
384 * <p>
385 * However, this form avoids superfluous object creation when the logger is disabled
386 * for level WARN.
387 * </p>
388 *
389 * @param format
390 * the format string
391 * @param arg1
392 * the first argument
393 * @param arg2
394 * the second argument
395 */
396 public void warn(String format, Object arg1, Object arg2) {
397 if (log.isWarnEnabled()) {
398 FormattingTuple ft = MessageFormatter.format(format, arg1, arg2);
399 log.warn(ft.getMessage(), ft.getThrowable());
400 }
401 }
402
403 /**
404 * Delegates to the {@link Log#warn(java.lang.Object)} method of the underlying
405 * {@link Log} instance.
406 *
407 * <p>
408 * However, this form avoids superfluous object creation when the logger is disabled
409 * for level WARN.
410 * </p>
411 *
412 * @param format the format string
413 * @param arguments a list of 3 or more arguments
414 */
415 public void warn(String format, Object... arguments) {
416 if (log.isWarnEnabled()) {
417 FormattingTuple ft = MessageFormatter.arrayFormat(format, arguments);
418 log.warn(ft.getMessage(), ft.getThrowable());
419 }
420 }
421
422 /**
423 * Delegates to the {@link Log#warn(java.lang.Object, java.lang.Throwable)} method of
424 * the underlying {@link Log} instance.
425 *
426 * @param msg
427 * the message accompanying the exception
428 * @param t
429 * the exception (throwable) to log
430 */
431
432 public void warn(String msg, Throwable t) {
433 log.warn(msg, t);
434 }
435
436 /**
437 * Delegates to the {@link Log#isErrorEnabled} method of the underlying
438 * {@link Log} instance.
439 */
440 public boolean isErrorEnabled() {
441 return log.isErrorEnabled();
442 }
443
444 /**
445 * Delegates to the {@link Log#error(java.lang.Object)} method of the underlying
446 * {@link Log} instance.
447 *
448 * @param msg - the message object to be logged
449 */
450 public void error(String msg) {
451 log.error(msg);
452 }
453
454 /**
455 * Delegates to the {@link Log#error(java.lang.Object)} method of the underlying
456 * {@link Log} instance.
457 *
458 * <p>
459 * However, this form avoids superfluous object creation when the logger is disabled
460 * for level ERROR.
461 * </p>
462 *
463 * @param format
464 * the format string
465 * @param arg
466 * the argument
467 */
468 public void error(String format, Object arg) {
469 if (log.isErrorEnabled()) {
470 FormattingTuple ft = MessageFormatter.format(format, arg);
471 log.error(ft.getMessage(), ft.getThrowable());
472 }
473 }
474
475 /**
476 * Delegates to the {@link Log#error(java.lang.Object)} method of the underlying
477 * {@link Log} instance.
478 *
479 * <p>
480 * However, this form avoids superfluous object creation when the logger is disabled
481 * for level ERROR.
482 * </p>
483 *
484 * @param format
485 * the format string
486 * @param arg1
487 * the first argument
488 * @param arg2
489 * the second argument
490 */
491 public void error(String format, Object arg1, Object arg2) {
492 if (log.isErrorEnabled()) {
493 FormattingTuple ft = MessageFormatter.format(format, arg1, arg2);
494 log.error(ft.getMessage(), ft.getThrowable());
495 }
496 }
497
498 /**
499 * Delegates to the {@link Log#error(java.lang.Object)} method of the underlying
500 * {@link Log} instance.
501 *
502 * <p>
503 * However, this form avoids superfluous object creation when the logger is disabled
504 * for level ERROR.
505 * </p>
506 *
507 * @param format the format string
508 * @param arguments a list of 3 or more arguments
509 */
510 public void error(String format, Object... arguments) {
511 if (log.isErrorEnabled()) {
512 FormattingTuple ft = MessageFormatter.arrayFormat(format, arguments);
513 log.error(ft.getMessage(), ft.getThrowable());
514 }
515 }
516
517 /**
518 * Delegates to the {@link Log#error(java.lang.Object, java.lang.Throwable)} method of
519 * the underlying {@link Log} instance.
520 *
521 * @param msg
522 * the message accompanying the exception
523 * @param t
524 * the exception (throwable) to log
525 */
526
527 public void error(String msg, Throwable t) {
528 log.error(msg, t);
529 }
530
531 }