1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.logging.log4j.appserver.jetty;
19
20 import org.apache.logging.log4j.Level;
21 import org.apache.logging.log4j.LogManager;
22 import org.apache.logging.log4j.spi.ExtendedLogger;
23 import org.apache.logging.log4j.spi.LoggerContext;
24 import org.eclipse.jetty.util.log.AbstractLogger;
25 import org.eclipse.jetty.util.log.Logger;
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46 public class Log4j2Logger extends AbstractLogger {
47
48 private static final String PARENT_FQCN = AbstractLogger.class.getName();
49
50
51
52
53 private static class PrivateManager extends LogManager {
54
55 public static LoggerContext getContext() {
56 final ClassLoader cl = AbstractLogger.class.getClassLoader();
57 return getContext(PARENT_FQCN, cl, false);
58 }
59
60 public static ExtendedLogger getLogger(final String name) {
61 return getContext().getLogger(name);
62 }
63 }
64
65 static final String FQCN = Log4j2Logger.class.getName();
66 private final ExtendedLogger logger;
67
68 private final String name;
69
70 public Log4j2Logger() {
71 this("");
72 }
73
74 public Log4j2Logger(final String name) {
75 super();
76 this.name = name;
77 this.logger = PrivateManager.getLogger(name);
78 }
79
80
81
82
83
84
85 @Override
86 public void debug(final String msg, final Object... args) {
87 logger.logIfEnabled(FQCN, Level.DEBUG, null, msg, args);
88 }
89
90
91
92
93
94
95 @Override
96 public void debug(final String msg, final Throwable thrown) {
97 logger.logIfEnabled(FQCN, Level.DEBUG, null, msg, thrown);
98 }
99
100
101
102
103
104
105 @Override
106 public void debug(final Throwable thrown) {
107 logger.logIfEnabled(FQCN, Level.DEBUG, null, (Object) null, thrown);
108 }
109
110
111
112
113
114
115 @Override
116 public String getName() {
117 return name;
118 }
119
120
121
122
123
124
125 @Override
126 public void ignore(final Throwable ignored) {
127
128 }
129
130
131
132
133
134
135 @Override
136 public void info(final String msg, final Object... args) {
137 logger.logIfEnabled(FQCN, Level.INFO, null, msg, args);
138 }
139
140
141
142
143
144
145 @Override
146 public void info(final String msg, final Throwable thrown) {
147 logger.logIfEnabled(FQCN, Level.INFO, null, msg, thrown);
148 }
149
150
151
152
153
154
155 @Override
156 public void info(final Throwable thrown) {
157 logger.logIfEnabled(FQCN, Level.INFO, null, (Object) null, thrown);
158 }
159
160
161
162
163
164
165 @Override
166 public boolean isDebugEnabled() {
167 return logger.isDebugEnabled();
168 }
169
170
171
172
173
174
175 @Override
176 protected Logger newLogger(final String fullname) {
177 return new Log4j2Logger(fullname);
178 }
179
180
181
182
183
184
185 @Override
186 public void setDebugEnabled(final boolean enabled) {
187 warn("setDebugEnabled not implemented");
188 }
189
190
191
192
193
194
195 @Override
196 public void warn(final String msg, final Object... args) {
197 logger.logIfEnabled(FQCN, Level.WARN, null, msg, args);
198 }
199
200
201
202
203
204
205 @Override
206 public void warn(final String msg, final Throwable thrown) {
207 logger.logIfEnabled(FQCN, Level.WARN, null, msg, thrown);
208 }
209
210
211
212
213
214
215 @Override
216 public void warn(final Throwable thrown) {
217 logger.logIfEnabled(FQCN, Level.WARN, null, (Object) null, thrown);
218 }
219
220 }