View Javadoc

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