|
1 |
| |
|
2 |
| |
|
3 |
| |
|
4 |
| |
|
5 |
| |
|
6 |
| |
|
7 |
| |
|
8 |
| |
|
9 |
| |
|
10 |
| |
|
11 |
| |
|
12 |
| |
|
13 |
| |
|
14 |
| |
|
15 |
| |
|
16 |
| |
|
17 |
| |
|
18 |
| |
|
19 |
| |
|
20 |
| |
|
21 |
| |
|
22 |
| |
|
23 |
| |
|
24 |
| |
|
25 |
| |
|
26 |
| |
|
27 |
| |
|
28 |
| |
|
29 |
| |
|
30 |
| |
|
31 |
| |
|
32 |
| |
|
33 |
| |
|
34 |
| |
|
35 |
| package edu.rice.cs.plt.debug; |
|
36 |
| |
|
37 |
| import java.io.File; |
|
38 |
| import java.io.Serializable; |
|
39 |
| import java.io.UnsupportedEncodingException; |
|
40 |
| import java.util.ArrayList; |
|
41 |
| import java.util.List; |
|
42 |
| import java.util.Timer; |
|
43 |
| import java.util.TimerTask; |
|
44 |
| |
|
45 |
| import edu.rice.cs.plt.iter.IterUtil; |
|
46 |
| import edu.rice.cs.plt.iter.SizedIterable; |
|
47 |
| import edu.rice.cs.plt.lambda.*; |
|
48 |
| import edu.rice.cs.plt.text.Bracket; |
|
49 |
| import edu.rice.cs.plt.text.TextUtil; |
|
50 |
| import edu.rice.cs.plt.tuple.Pair; |
|
51 |
| import edu.rice.cs.plt.reflect.ReflectUtil; |
|
52 |
| import edu.rice.cs.plt.reflect.ReflectException; |
|
53 |
| |
|
54 |
| |
|
55 |
| public final class DebugUtil { |
|
56 |
| |
|
57 |
| |
|
58 |
0
| private DebugUtil() {}
|
|
59 |
| |
|
60 |
| |
|
61 |
| |
|
62 |
| |
|
63 |
| |
|
64 |
| |
|
65 |
| |
|
66 |
| |
|
67 |
| |
|
68 |
| |
|
69 |
| public static volatile Log debug; |
|
70 |
| |
|
71 |
| |
|
72 |
| |
|
73 |
| |
|
74 |
| |
|
75 |
| |
|
76 |
| |
|
77 |
| |
|
78 |
| |
|
79 |
| |
|
80 |
| public static volatile Log error; |
|
81 |
| |
|
82 |
4
| static { initializeLogs(); }
|
|
83 |
| |
|
84 |
| |
|
85 |
| |
|
86 |
| |
|
87 |
| |
|
88 |
| |
|
89 |
| |
|
90 |
| |
|
91 |
4
| public static void initializeLogs() {
|
|
92 |
4
| String debugProp = System.getProperty("plt.debug.log");
|
|
93 |
4
| debug = (debugProp == null) ? VoidLog.INSTANCE : makeLog(debugProp, "Debug");
|
|
94 |
4
| String errorProp = System.getProperty("plt.error.log");
|
|
95 |
4
| error = (errorProp == null) ? VoidLog.INSTANCE : makeLog(errorProp, "Error");
|
|
96 |
| } |
|
97 |
| |
|
98 |
| |
|
99 |
| |
|
100 |
| |
|
101 |
| |
|
102 |
| |
|
103 |
| |
|
104 |
8
| public static Log makeLog(String descriptor, String defaultName) {
|
|
105 |
8
| LogSink sink = makeLogSink(descriptor, defaultName);
|
|
106 |
4
| if (sink == null) { return VoidLog.INSTANCE; }
|
|
107 |
4
| else { return new StandardLog(sink); }
|
|
108 |
| } |
|
109 |
| |
|
110 |
| |
|
111 |
| |
|
112 |
| |
|
113 |
| |
|
114 |
| |
|
115 |
| |
|
116 |
| |
|
117 |
| |
|
118 |
| |
|
119 |
| |
|
120 |
| |
|
121 |
| |
|
122 |
| |
|
123 |
| |
|
124 |
| |
|
125 |
| |
|
126 |
| |
|
127 |
| |
|
128 |
| |
|
129 |
| |
|
130 |
| |
|
131 |
| |
|
132 |
| |
|
133 |
| |
|
134 |
| |
|
135 |
| |
|
136 |
| |
|
137 |
| |
|
138 |
| |
|
139 |
| |
|
140 |
| |
|
141 |
| |
|
142 |
| |
|
143 |
| |
|
144 |
| |
|
145 |
| |
|
146 |
28
| public static LogSink makeLogSink(String descriptor, String defaultName) {
|
|
147 |
28
| String[] split = TextUtil.split(descriptor, ",", Bracket.PARENTHESES, Bracket.APOSTROPHES).array();
|
|
148 |
28
| List<LogSink> sinks = new ArrayList<LogSink>(split.length);
|
|
149 |
28
| for (String s : split) {
|
|
150 |
33
| LogSink sink = makeFilteredLogSink(s.trim(), defaultName);
|
|
151 |
28
| if (sink != null) { sinks.add(sink); }
|
|
152 |
| } |
|
153 |
5
| if (sinks.isEmpty()) { return null; }
|
|
154 |
18
| else if (sinks.size() == 1) { return sinks.get(0); }
|
|
155 |
5
| else { return new SplitLogSink(sinks); }
|
|
156 |
| } |
|
157 |
| |
|
158 |
33
| private static LogSink makeFilteredLogSink(String descriptor, String defaultName) {
|
|
159 |
33
| TextUtil.SplitString split = TextUtil.split(descriptor, "\\+|-", Bracket.PARENTHESES, Bracket.APOSTROPHES);
|
|
160 |
33
| String desc;
|
|
161 |
33
| SizedIterable<Pair<String, String>> filters;
|
|
162 |
26
| if (split.splits().isEmpty()) { desc = descriptor; filters = IterUtil.empty(); }
|
|
163 |
| else { |
|
164 |
7
| desc = split.splits().get(0).trim();
|
|
165 |
7
| Iterable<String> filterText = IterUtil.compose(IterUtil.skipFirst(split.splits()), split.rest());
|
|
166 |
7
| filters = IterUtil.zip(split.delimiters(), filterText);
|
|
167 |
| } |
|
168 |
| |
|
169 |
33
| LogSink result;
|
|
170 |
33
| if (desc.startsWith("(")) {
|
|
171 |
1
| if (desc.endsWith(")")) { result = makeLogSink(desc.substring(1, desc.length()-1), defaultName); }
|
|
172 |
0
| else { return null; }
|
|
173 |
| } |
|
174 |
32
| else if (desc.startsWith("~")) {
|
|
175 |
2
| result = new AsynchronousLogSink(makeAtomicLogSink(desc.substring(1), defaultName));
|
|
176 |
| } |
|
177 |
| else { |
|
178 |
30
| result = makeAtomicLogSink(desc, defaultName);
|
|
179 |
| } |
|
180 |
| |
|
181 |
33
| if (!filters.isEmpty()) {
|
|
182 |
7
| List<String> whiteListLocs = new ArrayList<String>();
|
|
183 |
7
| List<String> blackListLocs = new ArrayList<String>();
|
|
184 |
7
| List<String> whiteListThreads = new ArrayList<String>();
|
|
185 |
7
| List<String> blackListThreads = new ArrayList<String>();
|
|
186 |
7
| for (Pair<String, String> p : filters) {
|
|
187 |
11
| String text = p.second().trim();
|
|
188 |
11
| boolean thread = text.startsWith("'");
|
|
189 |
11
| if (thread) {
|
|
190 |
2
| if (text.endsWith("'")) { text = text.substring(1, text.length()-1); }
|
|
191 |
0
| else { return null; }
|
|
192 |
| } |
|
193 |
11
| if (p.first().equals("+")) {
|
|
194 |
6
| (thread ? whiteListThreads : whiteListLocs).add(text);
|
|
195 |
| } |
|
196 |
5
| else if (p.first().equals("-")) {
|
|
197 |
5
| (thread ? blackListThreads : blackListLocs).add(text);
|
|
198 |
| } |
|
199 |
0
| else { throw new RuntimeException("Bad delimiter from TextUtil.split: " + p.first()); }
|
|
200 |
| } |
|
201 |
7
| if (!blackListLocs.isEmpty()) {
|
|
202 |
2
| result = FilteredLogSink.byLocationBlackList(result, IterUtil.toArray(blackListLocs, String.class));
|
|
203 |
| } |
|
204 |
7
| if (!blackListThreads.isEmpty()) {
|
|
205 |
1
| result = FilteredLogSink.byThreadBlackList(result, IterUtil.toArray(blackListThreads, String.class));
|
|
206 |
| } |
|
207 |
7
| if (!whiteListLocs.isEmpty()) {
|
|
208 |
5
| result = FilteredLogSink.byLocationWhiteList(result, IterUtil.toArray(whiteListLocs, String.class));
|
|
209 |
| } |
|
210 |
7
| if (!whiteListThreads.isEmpty()) {
|
|
211 |
1
| result = FilteredLogSink.byThreadWhiteList(result, IterUtil.toArray(whiteListThreads, String.class));
|
|
212 |
| } |
|
213 |
| } |
|
214 |
33
| return result;
|
|
215 |
| } |
|
216 |
| |
|
217 |
32
| private static LogSink makeAtomicLogSink(String descriptor, String defaultName) {
|
|
218 |
32
| String[] split = TextUtil.split(descriptor, ":", 2, Bracket.PARENTHESES, Bracket.APOSTROPHES).array();
|
|
219 |
32
| String name = split[0].trim();
|
|
220 |
32
| String arg = (split.length > 1) ? split[1].trim() : "";
|
|
221 |
2
| if (arg.length() >= 2 && arg.startsWith("'") && arg.endsWith("'")) { arg = arg.substring(1, arg.length()-1); }
|
|
222 |
32
| LogSink result = null;
|
|
223 |
32
| String factoryName = System.getProperty("plt.log.factory");
|
|
224 |
32
| if (factoryName != null) {
|
|
225 |
0
| int dot = factoryName.lastIndexOf('.');
|
|
226 |
0
| if (dot >= 0) {
|
|
227 |
0
| String className = factoryName.substring(0, dot);
|
|
228 |
0
| String methodName = factoryName.substring(dot+1);
|
|
229 |
0
| try {
|
|
230 |
0
| result = (LogSink) ReflectUtil.invokeStaticMethod(className, methodName, name, arg, defaultName);
|
|
231 |
| } |
|
232 |
| catch (ReflectException e) { |
|
233 |
0
| System.err.println("Unable to invoke plt.log.factory: " + e.getCause());
|
|
234 |
| } |
|
235 |
| catch (ClassCastException e) { |
|
236 |
0
| System.err.println("Unable to invoke plt.log.factory: " + e);
|
|
237 |
| } |
|
238 |
| } |
|
239 |
| } |
|
240 |
32
| if (result == null) {
|
|
241 |
32
| try {
|
|
242 |
32
| if (name.equals("System.out") || name.equals("stdout")) {
|
|
243 |
4
| if (arg.equals("")) { result = new SystemOutLogSink(); }
|
|
244 |
1
| else { result = new SystemOutLogSink(arg); }
|
|
245 |
| } |
|
246 |
27
| else if (name.equals("System.err") || name.equals("stderr")) {
|
|
247 |
4
| if (arg.equals("")) { result = new SystemErrLogSink(); }
|
|
248 |
1
| else { result = new SystemErrLogSink(arg); }
|
|
249 |
| } |
|
250 |
22
| else if (name.equals("file")) {
|
|
251 |
2
| if (arg.equals("")) { arg = defaultName.toLowerCase().replace(' ', '-') + "-log.txt"; }
|
|
252 |
4
| String workingDir = System.getProperty("plt.log.working.dir");
|
|
253 |
4
| if (workingDir == null) { result = new FileLogSink(arg); }
|
|
254 |
0
| else { result = new FileLogSink(new File(workingDir, arg)); }
|
|
255 |
| } |
|
256 |
18
| else if (name.equals("assert")) {
|
|
257 |
7
| result = AssertEmptyLogSink.INSTANCE;
|
|
258 |
| } |
|
259 |
11
| else if (name.equals("popup")) {
|
|
260 |
4
| if (arg.equals("")) { arg = defaultName; }
|
|
261 |
4
| result = new PopupLogSink(arg);
|
|
262 |
| } |
|
263 |
7
| else if (name.equals("tree")) {
|
|
264 |
2
| if (arg.equals("")) { arg = defaultName; }
|
|
265 |
2
| result = remoteTreeLogSink(arg);
|
|
266 |
| } |
|
267 |
| |
|
268 |
| } |
|
269 |
| catch (Exception e) { } |
|
270 |
| } |
|
271 |
32
| return result;
|
|
272 |
| } |
|
273 |
| |
|
274 |
0
| public static Log voidLog() { return VoidLog.INSTANCE; }
|
|
275 |
0
| public static Log assertEmptyLog() { return new StandardLog(AssertEmptyLogSink.INSTANCE); }
|
|
276 |
0
| public static Log systemOutLog() { return new StandardLog(new SystemOutLogSink()); }
|
|
277 |
0
| public static Log systemOutLog(String charsetName) throws UnsupportedEncodingException {
|
|
278 |
0
| return new StandardLog(new SystemOutLogSink(charsetName));
|
|
279 |
| } |
|
280 |
0
| public static Log systemErrLog() { return new StandardLog(new SystemErrLogSink()); }
|
|
281 |
0
| public static Log systemErrLog(String charsetName) throws UnsupportedEncodingException {
|
|
282 |
0
| return new StandardLog(new SystemErrLogSink(charsetName));
|
|
283 |
| } |
|
284 |
0
| public static Log fileLog(String filename) { return new StandardLog(new FileLogSink(filename)); }
|
|
285 |
0
| public static Log fileLog(File f) { return new StandardLog(new FileLogSink(f)); }
|
|
286 |
0
| public static Log popupLog(String name) { return new StandardLog(new PopupLogSink(name)); }
|
|
287 |
0
| public static Log remoteTreeLog(String name) { return new StandardLog(remoteTreeLogSink(name)); }
|
|
288 |
| |
|
289 |
| |
|
290 |
| |
|
291 |
| |
|
292 |
| |
|
293 |
2
| public static LogSink remoteTreeLogSink(String name) {
|
|
294 |
2
| return new RMILogSink(TreeLogSink.factory(name, true), false);
|
|
295 |
| } |
|
296 |
| |
|
297 |
| |
|
298 |
| |
|
299 |
| |
|
300 |
| |
|
301 |
| |
|
302 |
| |
|
303 |
| |
|
304 |
| |
|
305 |
0
| public static boolean check(boolean assertion) {
|
|
306 |
0
| assert assertion;
|
|
307 |
0
| return assertion;
|
|
308 |
| } |
|
309 |
| |
|
310 |
| |
|
311 |
| |
|
312 |
| |
|
313 |
| |
|
314 |
| |
|
315 |
| |
|
316 |
0
| public static StackTraceElement getCaller() {
|
|
317 |
| |
|
318 |
| |
|
319 |
| |
|
320 |
0
| try { return new Throwable().getStackTrace()[2]; }
|
|
321 |
| catch (ArrayIndexOutOfBoundsException e) { |
|
322 |
0
| throw new IllegalStateException("Stack trace information for caller is not available");
|
|
323 |
| } |
|
324 |
| } |
|
325 |
| |
|
326 |
| |
|
327 |
| |
|
328 |
| private static final Thunk<Timer> LOG_TIMER = new LazyThunk<Timer>(new Thunk<Timer>() { |
|
329 |
0
| public Timer value() {
|
|
330 |
0
| return new Timer("Delayed Log Timer", true);
|
|
331 |
| } |
|
332 |
| }); |
|
333 |
| |
|
334 |
| |
|
335 |
| |
|
336 |
| |
|
337 |
| |
|
338 |
| |
|
339 |
| |
|
340 |
| |
|
341 |
| |
|
342 |
0
| public static void logThreadStatus(Log log, long... delays) {
|
|
343 |
0
| logThreadStatus(log, Thread.currentThread(), delays);
|
|
344 |
| } |
|
345 |
| |
|
346 |
| |
|
347 |
| |
|
348 |
| |
|
349 |
| |
|
350 |
| |
|
351 |
| |
|
352 |
| |
|
353 |
| |
|
354 |
| |
|
355 |
0
| public static void logThreadStatus(final Log log, final Thread thread, long... delays) {
|
|
356 |
| |
|
357 |
| class LogTask extends TimerTask { |
|
358 |
0
| public void run() {
|
|
359 |
0
| log.logValues(new String[]{ "thread", "state", "stack" },
|
|
360 |
| thread, thread.getState(), thread.getStackTrace()); |
|
361 |
| } |
|
362 |
| } |
|
363 |
0
| if (delays.length == 0) { new LogTask().run(); }
|
|
364 |
0
| for (final long delay : delays) {
|
|
365 |
0
| LOG_TIMER.value().schedule(new LogTask(), delay);
|
|
366 |
| } |
|
367 |
| } |
|
368 |
| |
|
369 |
| |
|
370 |
0
| public static Runnable logExceptions(Log l, Runnable r) {
|
|
371 |
0
| return new LogExceptionRunnable(l, r);
|
|
372 |
| } |
|
373 |
| |
|
374 |
| private static final class LogExceptionRunnable implements Runnable, Serializable { |
|
375 |
| private final Log _log; |
|
376 |
| private final Runnable _r; |
|
377 |
0
| public LogExceptionRunnable(Log log, Runnable r) { _log = log; _r = r; }
|
|
378 |
0
| public void run() {
|
|
379 |
0
| try { _r.run(); }
|
|
380 |
0
| catch (RuntimeException e) { _log.log(e); }
|
|
381 |
| } |
|
382 |
| } |
|
383 |
| |
|
384 |
| |
|
385 |
0
| public static Runnable logThrowables(Log l, Runnable r) {
|
|
386 |
0
| return new LogThrowableRunnable(l, r);
|
|
387 |
| } |
|
388 |
| |
|
389 |
| private static final class LogThrowableRunnable implements Runnable, Serializable { |
|
390 |
| private final Log _log; |
|
391 |
| private final Runnable _r; |
|
392 |
0
| public LogThrowableRunnable(Log log, Runnable r) { _log = log; _r = r; }
|
|
393 |
0
| public void run() {
|
|
394 |
0
| try { _r.run(); }
|
|
395 |
0
| catch (Throwable t) { _log.log(t); }
|
|
396 |
| } |
|
397 |
| } |
|
398 |
| |
|
399 |
| |
|
400 |
0
| public static <T> Runnable1<T> logExceptions(Log l, Runnable1<? super T> r) {
|
|
401 |
0
| return new LogExceptionRunnable1<T>(l, r);
|
|
402 |
| } |
|
403 |
| |
|
404 |
| private static final class LogExceptionRunnable1<T> implements Runnable1<T>, Serializable { |
|
405 |
| private final Log _log; |
|
406 |
| private final Runnable1<? super T> _r; |
|
407 |
0
| public LogExceptionRunnable1(Log log, Runnable1<? super T> r) { _log = log; _r = r; }
|
|
408 |
0
| public void run(T arg) {
|
|
409 |
0
| try { _r.run(arg); }
|
|
410 |
0
| catch (RuntimeException e) { _log.log(e); }
|
|
411 |
| } |
|
412 |
| } |
|
413 |
| |
|
414 |
| |
|
415 |
0
| public static <T> Runnable1<T> logThrowables(Log l, Runnable1<? super T> r) {
|
|
416 |
0
| return new LogThrowableRunnable1<T>(l, r);
|
|
417 |
| } |
|
418 |
| |
|
419 |
| private static final class LogThrowableRunnable1<T> implements Runnable1<T>, Serializable { |
|
420 |
| private final Log _log; |
|
421 |
| private final Runnable1<? super T> _r; |
|
422 |
0
| public LogThrowableRunnable1(Log log, Runnable1<? super T> r) { _log = log; _r = r; }
|
|
423 |
0
| public void run(T arg) {
|
|
424 |
0
| try { _r.run(arg); }
|
|
425 |
0
| catch (Throwable t) { _log.log(t); }
|
|
426 |
| } |
|
427 |
| } |
|
428 |
| |
|
429 |
| |
|
430 |
0
| public static <T1, T2> Runnable2<T1, T2> logExceptions(Log l, Runnable2<? super T1, ? super T2> r) {
|
|
431 |
0
| return new LogExceptionRunnable2<T1, T2>(l, r);
|
|
432 |
| } |
|
433 |
| |
|
434 |
| private static final class LogExceptionRunnable2<T1, T2> implements Runnable2<T1, T2>, Serializable { |
|
435 |
| private final Log _log; |
|
436 |
| private final Runnable2<? super T1, ? super T2> _r; |
|
437 |
0
| public LogExceptionRunnable2(Log log, Runnable2<? super T1, ? super T2> r) { _log = log; _r = r; }
|
|
438 |
0
| public void run(T1 arg1, T2 arg2) {
|
|
439 |
0
| try { _r.run(arg1, arg2); }
|
|
440 |
0
| catch (RuntimeException e) { _log.log(e); }
|
|
441 |
| } |
|
442 |
| } |
|
443 |
| |
|
444 |
| |
|
445 |
0
| public static <T1, T2> Runnable2<T1, T2> logThrowables(Log l, Runnable2<? super T1, ? super T2> r) {
|
|
446 |
0
| return new LogThrowableRunnable2<T1, T2>(l, r);
|
|
447 |
| } |
|
448 |
| |
|
449 |
| private static final class LogThrowableRunnable2<T1, T2> implements Runnable2<T1, T2>, Serializable { |
|
450 |
| private final Log _log; |
|
451 |
| private final Runnable2<? super T1, ? super T2> _r; |
|
452 |
0
| public LogThrowableRunnable2(Log log, Runnable2<? super T1, ? super T2> r) { _log = log; _r = r; }
|
|
453 |
0
| public void run(T1 arg1, T2 arg2) {
|
|
454 |
0
| try { _r.run(arg1, arg2); }
|
|
455 |
0
| catch (Throwable t) { _log.log(t); }
|
|
456 |
| } |
|
457 |
| } |
|
458 |
| |
|
459 |
| |
|
460 |
0
| public static <T1, T2, T3>
|
|
461 |
| Runnable3<T1, T2, T3> logExceptions(Log l, Runnable3<? super T1, ? super T2, ? super T3> r) { |
|
462 |
0
| return new LogExceptionRunnable3<T1, T2, T3>(l, r);
|
|
463 |
| } |
|
464 |
| |
|
465 |
| private static final class LogExceptionRunnable3<T1, T2, T3> implements Runnable3<T1, T2, T3>, Serializable { |
|
466 |
| private final Log _log; |
|
467 |
| private final Runnable3<? super T1, ? super T2, ? super T3> _r; |
|
468 |
0
| public LogExceptionRunnable3(Log log, Runnable3<? super T1, ? super T2, ? super T3> r) { _log = log; _r = r; }
|
|
469 |
0
| public void run(T1 arg1, T2 arg2, T3 arg3) {
|
|
470 |
0
| try { _r.run(arg1, arg2, arg3); }
|
|
471 |
0
| catch (RuntimeException e) { _log.log(e); }
|
|
472 |
| } |
|
473 |
| } |
|
474 |
| |
|
475 |
| |
|
476 |
0
| public static <T1, T2, T3>
|
|
477 |
| Runnable3<T1, T2, T3> logThrowables(Log l, Runnable3<? super T1, ? super T2, ? super T3> r) { |
|
478 |
0
| return new LogThrowableRunnable3<T1, T2, T3>(l, r);
|
|
479 |
| } |
|
480 |
| |
|
481 |
| private static final class LogThrowableRunnable3<T1, T2, T3> implements Runnable3<T1, T2, T3>, Serializable { |
|
482 |
| private final Log _log; |
|
483 |
| private final Runnable3<? super T1, ? super T2, ? super T3> _r; |
|
484 |
0
| public LogThrowableRunnable3(Log log, Runnable3<? super T1, ? super T2, ? super T3> r) { _log = log; _r = r; }
|
|
485 |
0
| public void run(T1 arg1, T2 arg2, T3 arg3) {
|
|
486 |
0
| try { _r.run(arg1, arg2, arg3); }
|
|
487 |
0
| catch (Throwable t) { _log.log(t); }
|
|
488 |
| } |
|
489 |
| } |
|
490 |
| |
|
491 |
| |
|
492 |
0
| public static <T1, T2, T3, T4>
|
|
493 |
| Runnable4<T1, T2, T3, T4> logExceptions(Log l, Runnable4<? super T1, ? super T2, ? super T3, ? super T4> r) { |
|
494 |
0
| return new LogExceptionRunnable4<T1, T2, T3, T4>(l, r);
|
|
495 |
| } |
|
496 |
| |
|
497 |
| private static final class LogExceptionRunnable4<T1, T2, T3, T4> implements Runnable4<T1, T2, T3, T4>, Serializable { |
|
498 |
| private final Log _log; |
|
499 |
| private final Runnable4<? super T1, ? super T2, ? super T3, ? super T4> _r; |
|
500 |
0
| public LogExceptionRunnable4(Log log, Runnable4<? super T1, ? super T2, ? super T3, ? super T4> r) {
|
|
501 |
0
| _log = log; _r = r;
|
|
502 |
| } |
|
503 |
0
| public void run(T1 arg1, T2 arg2, T3 arg3, T4 arg4) {
|
|
504 |
0
| try { _r.run(arg1, arg2, arg3, arg4); }
|
|
505 |
0
| catch (RuntimeException e) { _log.log(e); }
|
|
506 |
| } |
|
507 |
| } |
|
508 |
| |
|
509 |
| |
|
510 |
0
| public static <T1, T2, T3, T4>
|
|
511 |
| Runnable4<T1, T2, T3, T4> logThrowables(Log l, Runnable4<? super T1, ? super T2, ? super T3, ? super T4> r) { |
|
512 |
0
| return new LogThrowableRunnable4<T1, T2, T3, T4>(l, r);
|
|
513 |
| } |
|
514 |
| |
|
515 |
| private static final class LogThrowableRunnable4<T1, T2, T3, T4> implements Runnable4<T1, T2, T3, T4>, Serializable { |
|
516 |
| private final Log _log; |
|
517 |
| private final Runnable4<? super T1, ? super T2, ? super T3, ? super T4> _r; |
|
518 |
0
| public LogThrowableRunnable4(Log log, Runnable4<? super T1, ? super T2, ? super T3, ? super T4> r) {
|
|
519 |
0
| _log = log; _r = r;
|
|
520 |
| } |
|
521 |
0
| public void run(T1 arg1, T2 arg2, T3 arg3, T4 arg4) {
|
|
522 |
0
| try { _r.run(arg1, arg2, arg3, arg4); }
|
|
523 |
0
| catch (Throwable t) { _log.log(t); }
|
|
524 |
| } |
|
525 |
| } |
|
526 |
| |
|
527 |
| } |