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    *   https://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 io.netty.util.internal.ObjectUtil;
43  import org.apache.commons.logging.Log;
44  
45  /**
46   * <a href="https://commons.apache.org/logging/">Apache Commons Logging</a>
47   * logger.
48   *
49   * @deprecated Please use {@link Log4J2Logger} or {@link Log4JLogger} or
50   * {@link Slf4JLogger}.
51   */
52  @Deprecated
53  class CommonsLogger extends AbstractInternalLogger {
54  
55      private static final long serialVersionUID = 8647838678388394885L;
56  
57      private final transient Log logger;
58  
59      CommonsLogger(Log logger, String name) {
60          super(name);
61          this.logger = ObjectUtil.checkNotNull(logger, "logger");
62      }
63  
64      /**
65       * Delegates to the {@link Log#isTraceEnabled} method of the underlying
66       * {@link Log} instance.
67       */
68      @Override
69      public boolean isTraceEnabled() {
70          return logger.isTraceEnabled();
71      }
72  
73      /**
74       * Delegates to the {@link Log#trace(Object)} method of the underlying
75       * {@link Log} instance.
76       *
77       * @param msg - the message object to be logged
78       */
79      @Override
80      public void trace(String msg) {
81          logger.trace(msg);
82      }
83  
84      /**
85       * Delegates to the {@link Log#trace(Object)} method of the underlying
86       * {@link Log} instance.
87       *
88       * <p>
89       * However, this form avoids superfluous object creation when the logger is disabled
90       * for level TRACE.
91       * </p>
92       *
93       * @param format
94       *          the format string
95       * @param arg
96       *          the argument
97       */
98      @Override
99      public void trace(String format, Object arg) {
100         if (logger.isTraceEnabled()) {
101             FormattingTuple ft = MessageFormatter.format(format, arg);
102             logger.trace(ft.getMessage(), ft.getThrowable());
103         }
104     }
105 
106     /**
107      * Delegates to the {@link Log#trace(Object)} method of the underlying
108      * {@link Log} instance.
109      *
110      * <p>
111      * However, this form avoids superfluous object creation when the logger is disabled
112      * for level TRACE.
113      * </p>
114      *
115      * @param format
116      *          the format string
117      * @param argA
118      *          the first argument
119      * @param argB
120      *          the second argument
121      */
122     @Override
123     public void trace(String format, Object argA, Object argB) {
124         if (logger.isTraceEnabled()) {
125             FormattingTuple ft = MessageFormatter.format(format, argA, argB);
126             logger.trace(ft.getMessage(), ft.getThrowable());
127         }
128     }
129 
130     /**
131      * Delegates to the {@link Log#trace(Object)} method of the underlying
132      * {@link Log} instance.
133      *
134      * <p>
135      * However, this form avoids superfluous object creation when the logger is disabled
136      * for level TRACE.
137      * </p>
138      *
139      * @param format the format string
140      * @param arguments a list of 3 or more arguments
141      */
142     @Override
143     public void trace(String format, Object... arguments) {
144         if (logger.isTraceEnabled()) {
145             FormattingTuple ft = MessageFormatter.arrayFormat(format, arguments);
146             logger.trace(ft.getMessage(), ft.getThrowable());
147         }
148     }
149 
150     /**
151      * Delegates to the {@link Log#trace(Object, Throwable)} method of
152      * the underlying {@link Log} instance.
153      *
154      * @param msg
155      *          the message accompanying the exception
156      * @param t
157      *          the exception (throwable) to log
158      */
159     @Override
160     public void trace(String msg, Throwable t) {
161         logger.trace(msg, t);
162     }
163 
164     /**
165      * Delegates to the {@link Log#isDebugEnabled} method of the underlying
166      * {@link Log} instance.
167      */
168     @Override
169     public boolean isDebugEnabled() {
170         return logger.isDebugEnabled();
171     }
172 
173     //
174 
175     /**
176      * Delegates to the {@link Log#debug(Object)} method of the underlying
177      * {@link Log} instance.
178      *
179      * @param msg - the message object to be logged
180      */
181     @Override
182     public void debug(String msg) {
183         logger.debug(msg);
184     }
185 
186     /**
187      * Delegates to the {@link Log#debug(Object)} method of the underlying
188      * {@link Log} instance.
189      *
190      * <p>
191      * However, this form avoids superfluous object creation when the logger is disabled
192      * for level DEBUG.
193      * </p>
194      *
195      * @param format
196      *          the format string
197      * @param arg
198      *          the argument
199      */
200     @Override
201     public void debug(String format, Object arg) {
202         if (logger.isDebugEnabled()) {
203             FormattingTuple ft = MessageFormatter.format(format, arg);
204             logger.debug(ft.getMessage(), ft.getThrowable());
205         }
206     }
207 
208     /**
209      * Delegates to the {@link Log#debug(Object)} method of the underlying
210      * {@link Log} instance.
211      *
212      * <p>
213      * However, this form avoids superfluous object creation when the logger is disabled
214      * for level DEBUG.
215      * </p>
216      *
217      * @param format
218      *          the format string
219      * @param argA
220      *          the first argument
221      * @param argB
222      *          the second argument
223      */
224     @Override
225     public void debug(String format, Object argA, Object argB) {
226         if (logger.isDebugEnabled()) {
227             FormattingTuple ft = MessageFormatter.format(format, argA, argB);
228             logger.debug(ft.getMessage(), ft.getThrowable());
229         }
230     }
231 
232     /**
233      * Delegates to the {@link Log#debug(Object)} method of the underlying
234      * {@link Log} instance.
235      *
236      * <p>
237      * However, this form avoids superfluous object creation when the logger is disabled
238      * for level DEBUG.
239      * </p>
240      *
241      * @param format the format string
242      * @param arguments a list of 3 or more arguments
243      */
244     @Override
245     public void debug(String format, Object... arguments) {
246         if (logger.isDebugEnabled()) {
247             FormattingTuple ft = MessageFormatter.arrayFormat(format, arguments);
248             logger.debug(ft.getMessage(), ft.getThrowable());
249         }
250     }
251 
252     /**
253      * Delegates to the {@link Log#debug(Object, Throwable)} method of
254      * the underlying {@link Log} instance.
255      *
256      * @param msg
257      *          the message accompanying the exception
258      * @param t
259      *          the exception (throwable) to log
260      */
261     @Override
262     public void debug(String msg, Throwable t) {
263         logger.debug(msg, t);
264     }
265 
266     /**
267      * Delegates to the {@link Log#isInfoEnabled} method of the underlying
268      * {@link Log} instance.
269      */
270     @Override
271     public boolean isInfoEnabled() {
272         return logger.isInfoEnabled();
273     }
274 
275     /**
276      * Delegates to the {@link Log#debug(Object)} method of the underlying
277      * {@link Log} instance.
278      *
279      * @param msg - the message object to be logged
280      */
281     @Override
282     public void info(String msg) {
283         logger.info(msg);
284     }
285 
286     /**
287      * Delegates to the {@link Log#info(Object)} method of the underlying
288      * {@link Log} instance.
289      *
290      * <p>
291      * However, this form avoids superfluous object creation when the logger is disabled
292      * for level INFO.
293      * </p>
294      *
295      * @param format
296      *          the format string
297      * @param arg
298      *          the argument
299      */
300 
301     @Override
302     public void info(String format, Object arg) {
303         if (logger.isInfoEnabled()) {
304             FormattingTuple ft = MessageFormatter.format(format, arg);
305             logger.info(ft.getMessage(), ft.getThrowable());
306         }
307     }
308     /**
309      * Delegates to the {@link Log#info(Object)} method of the underlying
310      * {@link Log} instance.
311      *
312      * <p>
313      * However, this form avoids superfluous object creation when the logger is disabled
314      * for level INFO.
315      * </p>
316      *
317      * @param format
318      *          the format string
319      * @param argA
320      *          the first argument
321      * @param argB
322      *          the second argument
323      */
324     @Override
325     public void info(String format, Object argA, Object argB) {
326         if (logger.isInfoEnabled()) {
327             FormattingTuple ft = MessageFormatter.format(format, argA, argB);
328             logger.info(ft.getMessage(), ft.getThrowable());
329         }
330     }
331 
332     /**
333      * Delegates to the {@link Log#info(Object)} method of the underlying
334      * {@link Log} instance.
335      *
336      * <p>
337      * However, this form avoids superfluous object creation when the logger is disabled
338      * for level INFO.
339      * </p>
340      *
341      * @param format the format string
342      * @param arguments a list of 3 or more arguments
343      */
344     @Override
345     public void info(String format, Object... arguments) {
346         if (logger.isInfoEnabled()) {
347             FormattingTuple ft = MessageFormatter.arrayFormat(format, arguments);
348             logger.info(ft.getMessage(), ft.getThrowable());
349         }
350     }
351 
352     /**
353      * Delegates to the {@link Log#info(Object, Throwable)} method of
354      * the underlying {@link Log} instance.
355      *
356      * @param msg
357      *          the message accompanying the exception
358      * @param t
359      *          the exception (throwable) to log
360      */
361     @Override
362     public void info(String msg, Throwable t) {
363         logger.info(msg, t);
364     }
365 
366     /**
367      * Delegates to the {@link Log#isWarnEnabled} method of the underlying
368      * {@link Log} instance.
369      */
370     @Override
371     public boolean isWarnEnabled() {
372         return logger.isWarnEnabled();
373     }
374 
375     /**
376      * Delegates to the {@link Log#warn(Object)} method of the underlying
377      * {@link Log} instance.
378      *
379      * @param msg - the message object to be logged
380      */
381     @Override
382     public void warn(String msg) {
383         logger.warn(msg);
384     }
385 
386     /**
387      * Delegates to the {@link Log#warn(Object)} method of the underlying
388      * {@link Log} instance.
389      *
390      * <p>
391      * However, this form avoids superfluous object creation when the logger is disabled
392      * for level WARN.
393      * </p>
394      *
395      * @param format
396      *          the format string
397      * @param arg
398      *          the argument
399      */
400     @Override
401     public void warn(String format, Object arg) {
402         if (logger.isWarnEnabled()) {
403             FormattingTuple ft = MessageFormatter.format(format, arg);
404             logger.warn(ft.getMessage(), ft.getThrowable());
405         }
406     }
407 
408     /**
409      * Delegates to the {@link Log#warn(Object)} method of the underlying
410      * {@link Log} instance.
411      *
412      * <p>
413      * However, this form avoids superfluous object creation when the logger is disabled
414      * for level WARN.
415      * </p>
416      *
417      * @param format
418      *          the format string
419      * @param argA
420      *          the first argument
421      * @param argB
422      *          the second argument
423      */
424     @Override
425     public void warn(String format, Object argA, Object argB) {
426         if (logger.isWarnEnabled()) {
427             FormattingTuple ft = MessageFormatter.format(format, argA, argB);
428             logger.warn(ft.getMessage(), ft.getThrowable());
429         }
430     }
431 
432     /**
433      * Delegates to the {@link Log#warn(Object)} method of the underlying
434      * {@link Log} instance.
435      *
436      * <p>
437      * However, this form avoids superfluous object creation when the logger is disabled
438      * for level WARN.
439      * </p>
440      *
441      * @param format the format string
442      * @param arguments a list of 3 or more arguments
443      */
444     @Override
445     public void warn(String format, Object... arguments) {
446         if (logger.isWarnEnabled()) {
447             FormattingTuple ft = MessageFormatter.arrayFormat(format, arguments);
448             logger.warn(ft.getMessage(), ft.getThrowable());
449         }
450     }
451 
452     /**
453      * Delegates to the {@link Log#warn(Object, Throwable)} method of
454      * the underlying {@link Log} instance.
455      *
456      * @param msg
457      *          the message accompanying the exception
458      * @param t
459      *          the exception (throwable) to log
460      */
461 
462     @Override
463     public void warn(String msg, Throwable t) {
464         logger.warn(msg, t);
465     }
466 
467     /**
468      * Delegates to the {@link Log#isErrorEnabled} method of the underlying
469      * {@link Log} instance.
470      */
471     @Override
472     public boolean isErrorEnabled() {
473         return logger.isErrorEnabled();
474     }
475 
476     /**
477      * Delegates to the {@link Log#error(Object)} method of the underlying
478      * {@link Log} instance.
479      *
480      * @param msg - the message object to be logged
481      */
482     @Override
483     public void error(String msg) {
484         logger.error(msg);
485     }
486 
487     /**
488      * Delegates to the {@link Log#error(Object)} method of the underlying
489      * {@link Log} instance.
490      *
491      * <p>
492      * However, this form avoids superfluous object creation when the logger is disabled
493      * for level ERROR.
494      * </p>
495      *
496      * @param format
497      *          the format string
498      * @param arg
499      *          the argument
500      */
501     @Override
502     public void error(String format, Object arg) {
503         if (logger.isErrorEnabled()) {
504             FormattingTuple ft = MessageFormatter.format(format, arg);
505             logger.error(ft.getMessage(), ft.getThrowable());
506         }
507     }
508 
509     /**
510      * Delegates to the {@link Log#error(Object)} method of the underlying
511      * {@link Log} instance.
512      *
513      * <p>
514      * However, this form avoids superfluous object creation when the logger is disabled
515      * for level ERROR.
516      * </p>
517      *
518      * @param format
519      *          the format string
520      * @param argA
521      *          the first argument
522      * @param argB
523      *          the second argument
524      */
525     @Override
526     public void error(String format, Object argA, Object argB) {
527         if (logger.isErrorEnabled()) {
528             FormattingTuple ft = MessageFormatter.format(format, argA, argB);
529             logger.error(ft.getMessage(), ft.getThrowable());
530         }
531     }
532 
533     /**
534      * Delegates to the {@link Log#error(Object)} method of the underlying
535      * {@link Log} instance.
536      *
537      * <p>
538      * However, this form avoids superfluous object creation when the logger is disabled
539      * for level ERROR.
540      * </p>
541      *
542      * @param format the format string
543      * @param arguments a list of 3 or more arguments
544      */
545     @Override
546     public void error(String format, Object... arguments) {
547         if (logger.isErrorEnabled()) {
548             FormattingTuple ft = MessageFormatter.arrayFormat(format, arguments);
549             logger.error(ft.getMessage(), ft.getThrowable());
550         }
551     }
552 
553     /**
554      * Delegates to the {@link Log#error(Object, Throwable)} method of
555      * the underlying {@link Log} instance.
556      *
557      * @param msg
558      *          the message accompanying the exception
559      * @param t
560      *          the exception (throwable) to log
561      */
562     @Override
563     public void error(String msg, Throwable t) {
564         logger.error(msg, t);
565     }
566 }