001: /*
002: * Copyright (c) 2004-2008 QOS.ch
003: * All rights reserved.
004: *
005: * Permission is hereby granted, free of charge, to any person obtaining
006: * a copy of this software and associated documentation files (the
007: * "Software"), to deal in the Software without restriction, including
008: * without limitation the rights to use, copy, modify, merge, publish,
009: * distribute, sublicense, and/or sell copies of the Software, and to
010: * permit persons to whom the Software is furnished to do so, subject to
011: * the following conditions:
012: *
013: * The above copyright notice and this permission notice shall be
014: * included in all copies or substantial portions of the Software.
015: *
016: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
017: * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
018: * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
019: * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
020: * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
021: * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
022: * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
023: */
024:
025: package org.slf4j.impl;
026:
027: import org.apache.commons.logging.Log;
028: import org.slf4j.Logger;
029: import org.slf4j.helpers.MarkerIgnoringBase;
030: import org.slf4j.helpers.MessageFormatter;
031:
032: /**
033: * A wrapper over {@link org.apache.commons.logging.Log
034: * org.apache.commons.logging.Log} in conformance with the {@link Logger}
035: * interface.
036: *
037: * @author Ceki Gülcü
038: */
039: public final class JCLLoggerAdapter extends MarkerIgnoringBase {
040: final Log log;
041: final String name;
042:
043: // WARN: JCLLoggerAdapter constructor should have only package access so
044: // that only JCLLoggerFactory be able to create one.
045: JCLLoggerAdapter(Log log, String name) {
046: this .log = log;
047: this .name = name;
048: }
049:
050: public String getName() {
051: return name;
052: }
053:
054: /**
055: * Delegates to the {@link Log#isTraceEnabled} method of the underlying
056: * {@link Log} instance.
057: */
058: public boolean isTraceEnabled() {
059: return log.isTraceEnabled();
060: }
061:
062: //
063:
064: /**
065: * Delegates to the {@link Log#trace(java.lang.Object)} method of the underlying
066: * {@link Log} instance.
067: *
068: * @param msg - the message object to be logged
069: */
070: public void trace(String msg) {
071: log.trace(msg);
072: }
073:
074: /**
075: * Delegates to the {@link Log#trace(java.lang.Object)} method of the underlying
076: * {@link Log} instance.
077: *
078: * <p>
079: * However, this form avoids superfluous object creation when the logger is disabled
080: * for level TRACE.
081: * </p>
082: *
083: * @param format
084: * the format string
085: * @param arg
086: * the argument
087: */
088: public void trace(String format, Object arg) {
089: if (log.isDebugEnabled()) {
090: String msgStr = MessageFormatter.format(format, arg);
091: log.trace(msgStr);
092: }
093: }
094:
095: /**
096: * Delegates to the {@link Log#trace(java.lang.Object)} method of the underlying
097: * {@link Log} instance.
098: *
099: * <p>
100: * However, this form avoids superfluous object creation when the logger is disabled
101: * for level TRACE.
102: * </p>
103: *
104: * @param format
105: * the format string
106: * @param arg1
107: * the first argument
108: * @param arg2
109: * the second argument
110: */
111: public void trace(String format, Object arg1, Object arg2) {
112: if (log.isDebugEnabled()) {
113: String msgStr = MessageFormatter.format(format, arg1, arg2);
114: log.trace(msgStr);
115: }
116: }
117:
118: /**
119: * Delegates to the {@link Log#trace(java.lang.Object)} method of the underlying
120: * {@link Log} instance.
121: *
122: * <p>
123: * However, this form avoids superfluous object creation when the logger is disabled
124: * for level TRACE.
125: * </p>
126: *
127: * @param format the format string
128: * @param argArray an array of arguments
129: */
130: public void trace(String format, Object[] argArray) {
131: if (log.isDebugEnabled()) {
132: String msgStr = MessageFormatter.arrayFormat(format,
133: argArray);
134: log.trace(msgStr);
135: }
136: }
137:
138: /**
139: * Delegates to the {@link Log#trace(java.lang.Object, java.lang.Throwable)} method of
140: * the underlying {@link Log} instance.
141: *
142: * @param msg
143: * the message accompanying the exception
144: * @param t
145: * the exception (throwable) to log
146: */
147: public void trace(String msg, Throwable t) {
148: log.trace(msg, t);
149: }
150:
151: /**
152: * Delegates to the {@link Log#isDebugEnabled} method of the underlying
153: * {@link Log} instance.
154: */
155: public boolean isDebugEnabled() {
156: return log.isDebugEnabled();
157: }
158:
159: //
160:
161: /**
162: * Delegates to the {@link Log#debug(java.lang.Object)} method of the underlying
163: * {@link Log} instance.
164: *
165: * @param msg - the message object to be logged
166: */
167: public void debug(String msg) {
168: log.debug(msg);
169: }
170:
171: /**
172: * Delegates to the {@link Log#debug(java.lang.Object)} method of the underlying
173: * {@link Log} instance.
174: *
175: * <p>
176: * However, this form avoids superfluous object creation when the logger is disabled
177: * for level DEBUG.
178: * </p>
179: *
180: * @param format
181: * the format string
182: * @param arg
183: * the argument
184: */
185: public void debug(String format, Object arg) {
186: if (log.isDebugEnabled()) {
187: String msgStr = MessageFormatter.format(format, arg);
188: log.debug(msgStr);
189: }
190: }
191:
192: /**
193: * Delegates to the {@link Log#debug(java.lang.Object)} method of the underlying
194: * {@link Log} instance.
195: *
196: * <p>
197: * However, this form avoids superfluous object creation when the logger is disabled
198: * for level DEBUG.
199: * </p>
200: *
201: * @param format
202: * the format string
203: * @param arg1
204: * the first argument
205: * @param arg2
206: * the second argument
207: */
208: public void debug(String format, Object arg1, Object arg2) {
209: if (log.isDebugEnabled()) {
210: String msgStr = MessageFormatter.format(format, arg1, arg2);
211: log.debug(msgStr);
212: }
213: }
214:
215: /**
216: * Delegates to the {@link Log#debug(java.lang.Object)} method of the underlying
217: * {@link Log} instance.
218: *
219: * <p>
220: * However, this form avoids superfluous object creation when the logger is disabled
221: * for level DEBUG.
222: * </p>
223: *
224: * @param format the format string
225: * @param argArray an array of arguments
226: */
227: public void debug(String format, Object[] argArray) {
228: if (log.isDebugEnabled()) {
229: String msgStr = MessageFormatter.arrayFormat(format,
230: argArray);
231: log.debug(msgStr);
232: }
233: }
234:
235: /**
236: * Delegates to the {@link Log#debug(java.lang.Object, java.lang.Throwable)} method of
237: * the underlying {@link Log} instance.
238: *
239: * @param msg
240: * the message accompanying the exception
241: * @param t
242: * the exception (throwable) to log
243: */
244: public void debug(String msg, Throwable t) {
245: log.debug(msg, t);
246: }
247:
248: /**
249: * Delegates to the {@link Log#isInfoEnabled} method of the underlying
250: * {@link Log} instance.
251: */
252: public boolean isInfoEnabled() {
253: return log.isInfoEnabled();
254: }
255:
256: /**
257: * Delegates to the {@link Log#debug(java.lang.Object)} method of the underlying
258: * {@link Log} instance.
259: *
260: * @param msg - the message object to be logged
261: */
262: public void info(String msg) {
263: log.info(msg);
264: }
265:
266: /**
267: * Delegates to the {@link Log#info(java.lang.Object)} method of the underlying
268: * {@link Log} instance.
269: *
270: * <p>
271: * However, this form avoids superfluous object creation when the logger is disabled
272: * for level INFO.
273: * </p>
274: *
275: * @param format
276: * the format string
277: * @param arg
278: * the argument
279: */
280:
281: public void info(String format, Object arg) {
282: if (log.isInfoEnabled()) {
283: String msgStr = MessageFormatter.format(format, arg);
284: log.info(msgStr);
285: }
286: }
287:
288: /**
289: * Delegates to the {@link Log#info(java.lang.Object)} method of the underlying
290: * {@link Log} instance.
291: *
292: * <p>
293: * However, this form avoids superfluous object creation when the logger is disabled
294: * for level INFO.
295: * </p>
296: *
297: * @param format
298: * the format string
299: * @param arg1
300: * the first argument
301: * @param arg2
302: * the second argument
303: */
304: public void info(String format, Object arg1, Object arg2) {
305: if (log.isInfoEnabled()) {
306: String msgStr = MessageFormatter.format(format, arg1, arg2);
307: log.info(msgStr);
308: }
309: }
310:
311: /**
312: * Delegates to the {@link Log#info(java.lang.Object)} method of the underlying
313: * {@link Log} instance.
314: *
315: * <p>
316: * However, this form avoids superfluous object creation when the logger is disabled
317: * for level INFO.
318: * </p>
319: *
320: * @param format the format string
321: * @param argArray an array of arguments
322: */
323: public void info(String format, Object[] argArray) {
324: if (log.isInfoEnabled()) {
325: String msgStr = MessageFormatter.arrayFormat(format,
326: argArray);
327: log.info(msgStr);
328: }
329: }
330:
331: /**
332: * Delegates to the {@link Log#info(java.lang.Object, java.lang.Throwable)} method of
333: * the underlying {@link Log} instance.
334: *
335: * @param msg
336: * the message accompanying the exception
337: * @param t
338: * the exception (throwable) to log
339: */
340: public void info(String msg, Throwable t) {
341: log.info(msg, t);
342: }
343:
344: /**
345: * Delegates to the {@link Log#isWarnEnabled} method of the underlying
346: * {@link Log} instance.
347: */
348: public boolean isWarnEnabled() {
349: return log.isWarnEnabled();
350: }
351:
352: /**
353: * Delegates to the {@link Log#warn(java.lang.Object)} method of the underlying
354: * {@link Log} instance.
355: *
356: * @param msg - the message object to be logged
357: */
358: public void warn(String msg) {
359: log.warn(msg);
360: }
361:
362: /**
363: * Delegates to the {@link Log#warn(java.lang.Object)} method of the underlying
364: * {@link Log} instance.
365: *
366: * <p>
367: * However, this form avoids superfluous object creation when the logger is disabled
368: * for level WARN.
369: * </p>
370: *
371: * @param format
372: * the format string
373: * @param arg
374: * the argument
375: */
376: public void warn(String format, Object arg) {
377: if (log.isWarnEnabled()) {
378: String msgStr = MessageFormatter.format(format, arg);
379: log.warn(msgStr);
380: }
381: }
382:
383: /**
384: * Delegates to the {@link Log#warn(java.lang.Object)} method of the underlying
385: * {@link Log} instance.
386: *
387: * <p>
388: * However, this form avoids superfluous object creation when the logger is disabled
389: * for level WARN.
390: * </p>
391: *
392: * @param format
393: * the format string
394: * @param arg1
395: * the first argument
396: * @param arg2
397: * the second argument
398: */
399: public void warn(String format, Object arg1, Object arg2) {
400: if (log.isWarnEnabled()) {
401: String msgStr = MessageFormatter.format(format, arg1, arg2);
402: log.warn(msgStr);
403: }
404: }
405:
406: /**
407: * Delegates to the {@link Log#warn(java.lang.Object)} method of the underlying
408: * {@link Log} instance.
409: *
410: * <p>
411: * However, this form avoids superfluous object creation when the logger is disabled
412: * for level WARN.
413: * </p>
414: *
415: * @param format the format string
416: * @param argArray an array of arguments
417: */
418: public void warn(String format, Object[] argArray) {
419: if (log.isWarnEnabled()) {
420: String msgStr = MessageFormatter.arrayFormat(format,
421: argArray);
422: log.warn(msgStr);
423: }
424: }
425:
426: /**
427: * Delegates to the {@link Log#warn(java.lang.Object, java.lang.Throwable)} method of
428: * the underlying {@link Log} instance.
429: *
430: * @param msg
431: * the message accompanying the exception
432: * @param t
433: * the exception (throwable) to log
434: */
435:
436: public void warn(String msg, Throwable t) {
437: log.warn(msg, t);
438: }
439:
440: /**
441: * Delegates to the {@link Log#isErrorEnabled} method of the underlying
442: * {@link Log} instance.
443: */
444: public boolean isErrorEnabled() {
445: return log.isErrorEnabled();
446: }
447:
448: /**
449: * Delegates to the {@link Log#error(java.lang.Object)} method of the underlying
450: * {@link Log} instance.
451: *
452: * @param msg - the message object to be logged
453: */
454: public void error(String msg) {
455: log.error(msg);
456: }
457:
458: /**
459: * Delegates to the {@link Log#error(java.lang.Object)} method of the underlying
460: * {@link Log} instance.
461: *
462: * <p>
463: * However, this form avoids superfluous object creation when the logger is disabled
464: * for level ERROR.
465: * </p>
466: *
467: * @param format
468: * the format string
469: * @param arg
470: * the argument
471: */
472: public void error(String format, Object arg) {
473: if (log.isErrorEnabled()) {
474: String msgStr = MessageFormatter.format(format, arg);
475: log.error(msgStr);
476: }
477: }
478:
479: /**
480: * Delegates to the {@link Log#error(java.lang.Object)} method of the underlying
481: * {@link Log} instance.
482: *
483: * <p>
484: * However, this form avoids superfluous object creation when the logger is disabled
485: * for level ERROR.
486: * </p>
487: *
488: * @param format
489: * the format string
490: * @param arg1
491: * the first argument
492: * @param arg2
493: * the second argument
494: */
495: public void error(String format, Object arg1, Object arg2) {
496: if (log.isErrorEnabled()) {
497: String msgStr = MessageFormatter.format(format, arg1, arg2);
498: log.error(msgStr);
499: }
500: }
501:
502: /**
503: * Delegates to the {@link Log#error(java.lang.Object)} method of the underlying
504: * {@link Log} instance.
505: *
506: * <p>
507: * However, this form avoids superfluous object creation when the logger is disabled
508: * for level ERROR.
509: * </p>
510: *
511: * @param format the format string
512: * @param argArray an array of arguments
513: */
514: public void error(String format, Object[] argArray) {
515: if (log.isErrorEnabled()) {
516: String msgStr = MessageFormatter.arrayFormat(format,
517: argArray);
518: log.error(msgStr);
519: }
520: }
521:
522: /**
523: * Delegates to the {@link Log#error(java.lang.Object, java.lang.Throwable)} method of
524: * the underlying {@link Log} instance.
525: *
526: * @param msg
527: * the message accompanying the exception
528: * @param t
529: * the exception (throwable) to log
530: */
531:
532: public void error(String msg, Throwable t) {
533: log.error(msg, t);
534: }
535:
536: }
|