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  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          super();
30      }
31  
32      public boolean isEnabled(InternalLogLevel level) {
33          switch (level) {
34          case DEBUG:
35              return isDebugEnabled();
36          case INFO:
37              return isInfoEnabled();
38          case WARN:
39              return isWarnEnabled();
40          case ERROR:
41              return isErrorEnabled();
42          default:
43              throw new Error();
44          }
45      }
46  
47      public void log(InternalLogLevel level, String msg, Throwable cause) {
48          switch (level) {
49          case DEBUG:
50              debug(msg, cause);
51              break;
52          case INFO:
53              info(msg, cause);
54              break;
55          case WARN:
56              warn(msg, cause);
57              break;
58          case ERROR:
59              error(msg, cause);
60              break;
61          default:
62              throw new Error();
63          }
64      }
65  
66      public void log(InternalLogLevel level, String msg) {
67          switch (level) {
68          case DEBUG:
69              debug(msg);
70              break;
71          case INFO:
72              info(msg);
73              break;
74          case WARN:
75              warn(msg);
76              break;
77          case ERROR:
78              error(msg);
79              break;
80          default:
81              throw new Error();
82          }
83      }
84  }