View Javadoc
1   /*
2    * Copyright 2016 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 io.netty.util.internal.logging;
17  
18  
19  import org.apache.logging.log4j.Level;
20  import org.apache.logging.log4j.Logger;
21  import org.apache.logging.log4j.spi.ExtendedLogger;
22  import org.apache.logging.log4j.spi.ExtendedLoggerWrapper;
23  
24  class Log4J2Logger extends ExtendedLoggerWrapper implements InternalLogger {
25  
26      private static final long serialVersionUID = 5485418394879791397L;
27  
28      Log4J2Logger(Logger logger) {
29          super((ExtendedLogger) logger, logger.getName(), logger.getMessageFactory());
30      }
31  
32      @Override
33      public String name() {
34          return getName();
35      }
36  
37      @Override
38      public boolean isEnabled(InternalLogLevel level) {
39          return isEnabled(toLevel(level));
40      }
41  
42      @Override
43      public void log(InternalLogLevel level, String msg) {
44          log(toLevel(level), msg);
45      }
46  
47      @Override
48      public void log(InternalLogLevel level, String format, Object arg) {
49          log(toLevel(level), format, arg);
50      }
51  
52      @Override
53      public void log(InternalLogLevel level, String format, Object argA, Object argB) {
54          log(toLevel(level), format, argA, argB);
55      }
56  
57      @Override
58      public void log(InternalLogLevel level, String format, Object... arguments) {
59          log(toLevel(level), format, arguments);
60      }
61  
62      @Override
63      public void log(InternalLogLevel level, String msg, Throwable t) {
64          log(toLevel(level), msg, t);
65      }
66  
67      protected Level toLevel(InternalLogLevel level) {
68          switch (level) {
69              case INFO:
70                  return Level.INFO;
71              case DEBUG:
72                  return Level.DEBUG;
73              case WARN:
74                  return Level.WARN;
75              case ERROR:
76                  return Level.ERROR;
77              case TRACE:
78                  return Level.TRACE;
79              default:
80                  throw new Error();
81          }
82      }
83  }