View Javadoc
1   /**
2    *    Copyright 2009-2017 the original author or authors.
3    *
4    *    Licensed under the Apache License, Version 2.0 (the "License");
5    *    you may not use this file except in compliance with the License.
6    *    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,
12   *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   *    See the License for the specific language governing permissions and
14   *    limitations under the License.
15   */
16  package org.apache.ibatis.logging.log4j2;
17  
18  import org.apache.ibatis.logging.Log;
19  import org.apache.logging.log4j.LogManager;
20  import org.apache.logging.log4j.Logger;
21  import org.apache.logging.log4j.spi.AbstractLogger;
22  
23  /**
24   * @author Eduardo Macarron
25   */
26  public class Log4j2Impl implements Log {
27  
28    private final Log log;
29  
30    public Log4j2Impl(String clazz) {
31      Logger logger = LogManager.getLogger(clazz);
32  
33      if (logger instanceof AbstractLogger) {
34        log = new Log4j2AbstractLoggerImpl((AbstractLogger) logger);
35      } else {
36        log = new Log4j2LoggerImpl(logger);
37      }
38    }
39  
40    @Override
41    public boolean isDebugEnabled() {
42      return log.isDebugEnabled();
43    }
44  
45    @Override
46    public boolean isTraceEnabled() {
47      return log.isTraceEnabled();
48    }
49  
50    @Override
51    public void error(String s, Throwable e) {
52      log.error(s, e);
53    }
54  
55    @Override
56    public void error(String s) {
57      log.error(s);
58    }
59  
60    @Override
61    public void debug(String s) {
62      log.debug(s);
63    }
64  
65    @Override
66    public void trace(String s) {
67      log.trace(s);
68    }
69  
70    @Override
71    public void warn(String s) {
72      log.warn(s);
73    }
74  
75  }