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 this.name = name;
76 this.logger = PrivateManager.getLogger(name);
77 }
78
79
80
81
82
83
84 @Override
85 public void debug(final String msg, final Object... args) {
86 logger.logIfEnabled(FQCN, Level.DEBUG, null, msg, args);
87 }
88
89
90
91
92
93
94 @Override
95 public void debug(final String msg, final Throwable thrown) {
96 logger.logIfEnabled(FQCN, Level.DEBUG, null, msg, thrown);
97 }
98
99
100
101
102
103
104 @Override
105 public void debug(final Throwable thrown) {
106 logger.logIfEnabled(FQCN, Level.DEBUG, null, (Object) null, thrown);
107 }
108
109
110
111
112
113
114 @Override
115 public String getName() {
116 return name;
117 }
118
119
120
121
122
123
124 @Override
125 public void ignore(final Throwable ignored) {
126
127 }
128
129
130
131
132
133
134 @Override
135 public void info(final String msg, final Object... args) {
136 logger.logIfEnabled(FQCN, Level.INFO, null, msg, args);
137 }
138
139
140
141
142
143
144 @Override
145 public void info(final String msg, final Throwable thrown) {
146 logger.logIfEnabled(FQCN, Level.INFO, null, msg, thrown);
147 }
148
149
150
151
152
153
154 @Override
155 public void info(final Throwable thrown) {
156 logger.logIfEnabled(FQCN, Level.INFO, null, (Object) null, thrown);
157 }
158
159
160
161
162
163
164 @Override
165 public boolean isDebugEnabled() {
166 return logger.isDebugEnabled();
167 }
168
169
170
171
172
173
174 @Override
175 protected Logger newLogger(final String fullname) {
176 return new Log4j2Logger(fullname);
177 }
178
179
180
181
182
183
184 @Override
185 public void setDebugEnabled(final boolean enabled) {
186 warn("setDebugEnabled not implemented");
187 }
188
189
190
191
192
193
194 @Override
195 public void warn(final String msg, final Object... args) {
196 logger.logIfEnabled(FQCN, Level.WARN, null, msg, args);
197 }
198
199
200
201
202
203
204 @Override
205 public void warn(final String msg, final Throwable thrown) {
206 logger.logIfEnabled(FQCN, Level.WARN, null, msg, thrown);
207 }
208
209
210
211
212
213
214 @Override
215 public void warn(final Throwable thrown) {
216 logger.logIfEnabled(FQCN, Level.WARN, null, (Object) null, thrown);
217 }
218
219 }