1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.apache.ibatis.logging.slf4j;
17
18 import org.apache.ibatis.logging.Log;
19 import org.slf4j.Logger;
20 import org.slf4j.LoggerFactory;
21 import org.slf4j.Marker;
22 import org.slf4j.spi.LocationAwareLogger;
23
24
25
26
27
28 public class Slf4jImpl implements Log {
29
30 private Log log;
31
32 public Slf4jImpl(String clazz) {
33 Logger logger = LoggerFactory.getLogger(clazz);
34
35 if (logger instanceof LocationAwareLogger) {
36 try {
37
38 logger.getClass().getMethod("log", Marker.class, String.class, int.class, String.class, Object[].class,
39 Throwable.class);
40 log = new Slf4jLocationAwareLoggerImpl((LocationAwareLogger) logger);
41 return;
42 } catch (SecurityException | NoSuchMethodException e) {
43
44 }
45 }
46
47
48 log = new Slf4jLoggerImpl(logger);
49 }
50
51 @Override
52 public boolean isDebugEnabled() {
53 return log.isDebugEnabled();
54 }
55
56 @Override
57 public boolean isTraceEnabled() {
58 return log.isTraceEnabled();
59 }
60
61 @Override
62 public void error(String s, Throwable e) {
63 log.error(s, e);
64 }
65
66 @Override
67 public void error(String s) {
68 log.error(s);
69 }
70
71 @Override
72 public void debug(String s) {
73 log.debug(s);
74 }
75
76 @Override
77 public void trace(String s) {
78 log.trace(s);
79 }
80
81 @Override
82 public void warn(String s) {
83 log.warn(s);
84 }
85
86 }