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.slf4j;
17  
18  import org.mybatis.generator.logging.Log;
19  import org.mybatis.generator.logging.LogFactory;
20  import org.slf4j.Marker;
21  import org.slf4j.MarkerFactory;
22  import org.slf4j.spi.LocationAwareLogger;
23  
24  class Slf4jLocationAwareLoggerImpl implements Log {
25  
26      private static final Marker MARKER = MarkerFactory.getMarker(LogFactory.MARKER);
27  
28      private static final String FQCN = Slf4jImpl.class.getName();
29  
30      private final LocationAwareLogger logger;
31  
32      Slf4jLocationAwareLoggerImpl(LocationAwareLogger logger) {
33          this.logger = logger;
34      }
35  
36      @Override
37      public boolean isDebugEnabled() {
38          return logger.isDebugEnabled();
39      }
40  
41      @Override
42      public void error(String s, Throwable e) {
43          logger.log(MARKER, FQCN, LocationAwareLogger.ERROR_INT, s, null, e);
44      }
45  
46      @Override
47      public void error(String s) {
48          logger.log(MARKER, FQCN, LocationAwareLogger.ERROR_INT, s, null, null);
49      }
50  
51      @Override
52      public void debug(String s) {
53          logger.log(MARKER, FQCN, LocationAwareLogger.DEBUG_INT, s, null, null);
54      }
55  
56      @Override
57      public void warn(String s) {
58          logger.log(MARKER, FQCN, LocationAwareLogger.WARN_INT, s, null, null);
59      }
60  
61      @Override
62      public void info(String s) {
63          logger.log(MARKER, FQCN, LocationAwareLogger.INFO_INT, s, null, null);
64      }
65  }