1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.apache.ibatis.logging.log4j2;
17
18 import org.apache.ibatis.logging.Log;
19 import org.apache.ibatis.logging.LogFactory;
20 import org.apache.logging.log4j.Level;
21 import org.apache.logging.log4j.Marker;
22 import org.apache.logging.log4j.MarkerManager;
23 import org.apache.logging.log4j.message.Message;
24 import org.apache.logging.log4j.message.SimpleMessage;
25 import org.apache.logging.log4j.spi.AbstractLogger;
26 import org.apache.logging.log4j.spi.ExtendedLoggerWrapper;
27
28
29
30
31 public class Log4j2AbstractLoggerImpl implements Log {
32
33 private static final Marker MARKER = MarkerManager.getMarker(LogFactory.MARKER);
34
35 private static final String FQCN = Log4j2Impl.class.getName();
36
37 private final ExtendedLoggerWrapper log;
38
39 public Log4j2AbstractLoggerImpl(AbstractLogger abstractLogger) {
40 log = new ExtendedLoggerWrapper(abstractLogger, abstractLogger.getName(), abstractLogger.getMessageFactory());
41 }
42
43 @Override
44 public boolean isDebugEnabled() {
45 return log.isDebugEnabled();
46 }
47
48 @Override
49 public boolean isTraceEnabled() {
50 return log.isTraceEnabled();
51 }
52
53 @Override
54 public void error(String s, Throwable e) {
55 log.logIfEnabled(FQCN, Level.ERROR, MARKER, (Message) new SimpleMessage(s), e);
56 }
57
58 @Override
59 public void error(String s) {
60 log.logIfEnabled(FQCN, Level.ERROR, MARKER, (Message) new SimpleMessage(s), null);
61 }
62
63 @Override
64 public void debug(String s) {
65 log.logIfEnabled(FQCN, Level.DEBUG, MARKER, (Message) new SimpleMessage(s), null);
66 }
67
68 @Override
69 public void trace(String s) {
70 log.logIfEnabled(FQCN, Level.TRACE, MARKER, (Message) new SimpleMessage(s), null);
71 }
72
73 @Override
74 public void warn(String s) {
75 log.logIfEnabled(FQCN, Level.WARN, MARKER, (Message) new SimpleMessage(s), null);
76 }
77
78 }