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 package org.archive.crawler.io;
26
27 import java.io.PrintWriter;
28 import java.io.StringWriter;
29 import java.util.logging.LogRecord;
30
31 import org.archive.crawler.datamodel.CoreAttributeConstants;
32 import org.archive.crawler.datamodel.CrawlURI;
33
34 /***
35 * Runtime exception log formatter.
36 *
37 * Used to format unexpected runtime exceptions such as
38 * OOMEs.
39 *
40 * @author gojomo
41 */
42 public class RuntimeErrorFormatter extends UriProcessingFormatter
43 implements CoreAttributeConstants {
44 public String format(LogRecord lr) {
45 Object [] parameters = lr.getParameters();
46 String stackTrace = "None retrieved";
47 if (parameters != null) {
48
49 CrawlURI curi = (CrawlURI)parameters[0];
50 if (curi != null) {
51 Throwable t = (Throwable)curi.getObject(A_RUNTIME_EXCEPTION);
52 assert t != null : "Null throwable";
53 StringWriter sw = new StringWriter();
54 if (t == null) {
55 sw.write("No exception to report.");
56 } else {
57 t.printStackTrace(new PrintWriter(sw));
58 }
59 stackTrace = sw.toString();
60 }
61 }
62 return super.format(lr) + " " + stackTrace;
63 }
64 }