查看本类的 API文档回源码主页即时通讯网 - 即时通讯开发者社区!
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  package org.jboss.netty.logging;
17  
18  /**
19   * A skeletal implementation of {@link InternalLogger}.  This class implements
20   * all methods that have a {@link InternalLogLevel} parameter by default to call
21   * specific logger methods such as {@link #info(String)} or {@link #isInfoEnabled()}.
22   */
23  public abstract class AbstractInternalLogger implements InternalLogger {
24  
25      /**
26       * Creates a new instance.
27       */
28      protected AbstractInternalLogger() {
29      }
30  
31      public boolean isEnabled(InternalLogLevel level) {
32          switch (level) {
33          case DEBUG:
34              return isDebugEnabled();
35          case INFO:
36              return isInfoEnabled();
37          case WARN:
38              return isWarnEnabled();
39          case ERROR:
40              return isErrorEnabled();
41          default:
42              throw new Error();
43          }
44      }
45  
46      public void log(InternalLogLevel level, String msg, Throwable cause) {
47          switch (level) {
48          case DEBUG:
49              debug(msg, cause);
50              break;
51          case INFO:
52              info(msg, cause);
53              break;
54          case WARN:
55              warn(msg, cause);
56              break;
57          case ERROR:
58              error(msg, cause);
59              break;
60          default:
61              throw new Error();
62          }
63      }
64  
65      public void log(InternalLogLevel level, String msg) {
66          switch (level) {
67          case DEBUG:
68              debug(msg);
69              break;
70          case INFO:
71              info(msg);
72              break;
73          case WARN:
74              warn(msg);
75              break;
76          case ERROR:
77              error(msg);
78              break;
79          default:
80              throw new Error();
81          }
82      }
83  }