1
2
3
4
5
6
7
8
9
10
11
12
13
14 package org.eclipse.jetty.util.log;
15
16 import java.lang.reflect.Method;
17 import java.security.AccessController;
18 import java.security.PrivilegedAction;
19
20 import org.eclipse.jetty.util.Loader;
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38 public class Log
39 {
40 public final static String EXCEPTION= "EXCEPTION ";
41 public final static String IGNORED= "IGNORED ";
42
43 public static String __logClass;
44 public static boolean __ignored;
45
46 static
47 {
48 AccessController.doPrivileged(new PrivilegedAction<Object>()
49 {
50 public Object run()
51 {
52 __logClass = System.getProperty("org.eclipse.jetty.util.log.class", "org.eclipse.jetty.util.log.Slf4jLog");
53 __ignored = Boolean.parseBoolean(System.getProperty("org.eclipse.jetty.util.log.IGNORED", "false"));
54 return null;
55 }
56 });
57 }
58
59 private static Logger LOG;
60 private static boolean __initialized;
61
62 public static boolean initialized()
63 {
64 if (LOG != null)
65 return true;
66
67 synchronized (Log.class)
68 {
69 if (__initialized)
70 return LOG != null;
71 __initialized = true;
72 }
73
74 try
75 {
76 Class<?> log_class = Loader.loadClass(Log.class, __logClass);
77 if (LOG == null || !LOG.getClass().equals(log_class))
78 {
79 LOG = (Logger)log_class.newInstance();
80 LOG.debug("Logging to {} via {}", LOG, log_class.getName());
81 }
82 }
83 catch(Throwable e)
84 {
85 if (e instanceof ThreadDeath)
86 throw (ThreadDeath)e;
87
88 initStandardLogging(e);
89 }
90
91 return LOG != null;
92 }
93
94 private static void initStandardLogging(Throwable e)
95 {
96 Class<?> log_class;
97 if(e != null && __ignored)
98 e.printStackTrace();
99 if (LOG == null)
100 {
101 log_class = StdErrLog.class;
102 LOG = new StdErrLog();
103 LOG.debug("Logging to {} via {}", LOG, log_class.getName());
104 }
105 }
106
107 public static void setLog(Logger log)
108 {
109 Log.LOG = log;
110 }
111
112
113
114
115 @Deprecated
116 public static Logger getLog()
117 {
118 initialized();
119 return LOG;
120 }
121
122
123
124
125
126 public static Logger getRootLogger() {
127 initialized();
128 return LOG;
129 }
130
131 static boolean isIgnored()
132 {
133 return __ignored;
134 }
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151 public static void setLogToParent(String name)
152 {
153 ClassLoader loader = Log.class.getClassLoader();
154 if (loader.getParent()!=null)
155 {
156 try
157 {
158 Class<?> uberlog = loader.getParent().loadClass("org.eclipse.jetty.util.log.Log");
159 Method getLogger = uberlog.getMethod("getLogger", new Class[]{String.class});
160 Object logger = getLogger.invoke(null,name);
161 setLog(new LoggerLog(logger));
162 }
163 catch (Exception e)
164 {
165 e.printStackTrace();
166 }
167 }
168 else
169 {
170 setLog(getLogger(name));
171 }
172 }
173
174
175
176
177 @Deprecated
178 public static void debug(Throwable th)
179 {
180 if (!isDebugEnabled())
181 return;
182 LOG.debug(EXCEPTION, th);
183 }
184
185
186
187
188 @Deprecated
189 public static void debug(String msg)
190 {
191 if (!initialized())
192 return;
193 LOG.debug(msg);
194 }
195
196
197
198
199 @Deprecated
200 public static void debug(String msg, Object arg)
201 {
202 if (!initialized())
203 return;
204 LOG.debug(msg, arg);
205 }
206
207
208
209
210 @Deprecated
211 public static void debug(String msg, Object arg0, Object arg1)
212 {
213 if (!initialized())
214 return;
215 LOG.debug(msg, arg0, arg1);
216 }
217
218
219
220
221
222
223
224
225
226 @Deprecated
227 public static void ignore(Throwable thrown)
228 {
229 if (!initialized())
230 return;
231 LOG.ignore(thrown);
232 }
233
234
235
236
237 @Deprecated
238 public static void info(String msg)
239 {
240 if (!initialized())
241 return;
242 LOG.info(msg);
243 }
244
245
246
247
248 @Deprecated
249 public static void info(String msg, Object arg)
250 {
251 if (!initialized())
252 return;
253 LOG.info(msg, arg);
254 }
255
256
257
258
259 @Deprecated
260 public static void info(String msg, Object arg0, Object arg1)
261 {
262 if (!initialized())
263 return;
264 LOG.info(msg, arg0, arg1);
265 }
266
267
268
269
270 @Deprecated
271 public static boolean isDebugEnabled()
272 {
273 if (!initialized())
274 return false;
275 return LOG.isDebugEnabled();
276 }
277
278
279
280
281 @Deprecated
282 public static void warn(String msg)
283 {
284 if (!initialized())
285 return;
286 LOG.warn(msg);
287 }
288
289
290
291
292 @Deprecated
293 public static void warn(String msg, Object arg)
294 {
295 if (!initialized())
296 return;
297 LOG.warn(msg, arg);
298 }
299
300
301
302
303 @Deprecated
304 public static void warn(String msg, Object arg0, Object arg1)
305 {
306 if (!initialized())
307 return;
308 LOG.warn(msg, arg0, arg1);
309 }
310
311
312
313
314 @Deprecated
315 public static void warn(String msg, Throwable th)
316 {
317 if (!initialized())
318 return;
319 LOG.warn(msg, th);
320 }
321
322
323
324
325 @Deprecated
326 public static void warn(Throwable th)
327 {
328 if (!initialized())
329 return;
330 LOG.warn(EXCEPTION, th);
331 }
332
333
334
335
336
337
338
339
340 public static Logger getLogger(Class<?> clazz)
341 {
342 return getLogger(clazz.getName());
343 }
344
345
346
347
348
349
350 public static Logger getLogger(String name)
351 {
352 if (!initialized())
353 return null;
354
355 return name == null ? LOG : LOG.getLogger(name);
356 }
357 }