View Javadoc
1   /*
2    *    Copyright 2006-2023 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    *       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,
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.mybatis.generator.logging.log4j2;
17  
18  import org.apache.logging.log4j.LogManager;
19  import org.apache.logging.log4j.Logger;
20  import org.apache.logging.log4j.spi.AbstractLogger;
21  import org.mybatis.generator.logging.Log;
22  
23  public class Log4j2Impl implements Log {
24  
25      private final Log log;
26  
27      public Log4j2Impl(Class<?> clazz) {
28          Logger logger = LogManager.getLogger(clazz);
29  
30          if (logger instanceof AbstractLogger) {
31              log = new Log4j2AbstractLoggerImpl((AbstractLogger) logger);
32          } else {
33              log = new Log4j2LoggerImpl(logger);
34          }
35      }
36  
37      @Override
38      public boolean isDebugEnabled() {
39          return log.isDebugEnabled();
40      }
41  
42      @Override
43      public void error(String s, Throwable e) {
44          log.error(s, e);
45      }
46  
47      @Override
48      public void error(String s) {
49          log.error(s);
50      }
51  
52      @Override
53      public void debug(String s) {
54          log.debug(s);
55      }
56  
57      @Override
58      public void warn(String s) {
59          log.warn(s);
60      }
61  
62      @Override
63      public void info(String s) {
64          log.info(s);
65      }
66  }