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.SimpleMessage;
24 import org.apache.logging.log4j.spi.AbstractLogger;
25 import org.apache.logging.log4j.spi.ExtendedLoggerWrapper;
26
27
28
29
30 public class Log4j2AbstractLoggerImpl implements Log {
31
32 private static Marker MARKER = MarkerManager.getMarker(LogFactory.MARKER);
33
34 private static final String FQCN = Log4j2Impl.class.getName();
35
36 private ExtendedLoggerWrapper log;
37
38 public Log4j2AbstractLoggerImpl(AbstractLogger abstractLogger) {
39 log = new ExtendedLoggerWrapper(abstractLogger, abstractLogger.getName(), abstractLogger.getMessageFactory());
40 }
41
42 @Override
43 public boolean isDebugEnabled() {
44 return log.isDebugEnabled();
45 }
46
47 @Override
48 public boolean isTraceEnabled() {
49 return log.isTraceEnabled();
50 }
51
52 @Override
53 public void error(String s, Throwable e) {
54 log.logIfEnabled(FQCN, Level.ERROR, MARKER, new SimpleMessage(s), e);
55 }
56
57 @Override
58 public void error(String s) {
59 log.logIfEnabled(FQCN, Level.ERROR, MARKER, new SimpleMessage(s), null);
60 }
61
62 @Override
63 public void debug(String s) {
64 log.logIfEnabled(FQCN, Level.DEBUG, MARKER, new SimpleMessage(s), null);
65 }
66
67 @Override
68 public void trace(String s) {
69 log.logIfEnabled(FQCN, Level.TRACE, MARKER, new SimpleMessage(s), null);
70 }
71
72 @Override
73 public void warn(String s) {
74 log.logIfEnabled(FQCN, Level.WARN, MARKER, new SimpleMessage(s), null);
75 }
76
77 }