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, Throwable.class);
39 log = new Slf4jLocationAwareLoggerImpl((LocationAwareLogger) logger);
40 return;
41 } catch (SecurityException e) {
42
43 } catch (NoSuchMethodException e) {
44
45 }
46 }
47
48
49 log = new Slf4jLoggerImpl(logger);
50 }
51
52 @Override
53 public boolean isDebugEnabled() {
54 return log.isDebugEnabled();
55 }
56
57 @Override
58 public boolean isTraceEnabled() {
59 return log.isTraceEnabled();
60 }
61
62 @Override
63 public void error(String s, Throwable e) {
64 log.error(s, e);
65 }
66
67 @Override
68 public void error(String s) {
69 log.error(s);
70 }
71
72 @Override
73 public void debug(String s) {
74 log.debug(s);
75 }
76
77 @Override
78 public void trace(String s) {
79 log.trace(s);
80 }
81
82 @Override
83 public void warn(String s) {
84 log.warn(s);
85 }
86
87 }