1 /* RuntimeErrorFormatter
2 *
3 * Created on Jul 7, 2003
4 *
5 * $Id: RuntimeErrorFormatter.java 3124 2005-02-17 23:51:25Z gojomo $
6 *
7 * Copyright (C) 2003 Internet Archive.
8 *
9 * This file is part of the Heritrix web crawler (crawler.archive.org).
10 *
11 * Heritrix is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser Public License as published by
13 * the Free Software Foundation; either version 2.1 of the License, or
14 * any later version.
15 *
16 * Heritrix is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser Public License for more details.
20 *
21 * You should have received a copy of the GNU Lesser Public License
22 * along with Heritrix; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
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 // CrawlURI is always first parameter.
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 }