1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package liquibase.ext.logging.log4j2;
18
19 import liquibase.logging.core.AbstractLogger;
20
21 import org.apache.logging.log4j.Level;
22 import org.apache.logging.log4j.LogManager;
23 import org.apache.logging.log4j.spi.ExtendedLogger;
24
25
26
27
28
29
30
31 public class Log4j2Logger extends AbstractLogger {
32
33 private static final String FQCN = Log4j2Logger.class.getName();
34
35 private ExtendedLogger logger;
36
37 @Override
38 public void debug(final String message) {
39 logger.logIfEnabled(FQCN, Level.DEBUG, null, buildMessage(message));
40 }
41
42 @Override
43 public void debug(final String message, final Throwable e) {
44 logger.logIfEnabled(FQCN, Level.DEBUG, null, buildMessage(message), e);
45 }
46
47 @Override
48 public int getPriority() {
49 return PRIORITY_DATABASE;
50 }
51
52 @Override
53 public void info(final String message) {
54 logger.logIfEnabled(FQCN, Level.INFO, null, buildMessage(message));
55 }
56
57 @Override
58 public void info(final String message, final Throwable e) {
59 logger.logIfEnabled(FQCN, Level.INFO, null, buildMessage(message), e);
60 }
61
62 @Override
63 public void setLogLevel(final String logLevel, final String logFile) {
64 setLogLevel(logLevel);
65
66 }
67
68 @Override
69 public void setName(final String name) {
70 logger = LogManager.getContext(false).getLogger(name);
71 }
72
73 @Override
74 public void severe(final String message) {
75 logger.logIfEnabled(FQCN, Level.ERROR, null, buildMessage(message));
76 }
77
78 @Override
79 public void severe(final String message, final Throwable e) {
80 logger.logIfEnabled(FQCN, Level.ERROR, null, buildMessage(message), e);
81 }
82
83 @Override
84 public void warning(final String message) {
85 logger.logIfEnabled(FQCN, Level.WARN, null, buildMessage(message));
86 }
87
88 @Override
89 public void warning(final String message, final Throwable e) {
90 logger.logIfEnabled(FQCN, Level.WARN, null, buildMessage(message), e);
91 }
92
93 }