01: /* RuntimeErrorFormatter
02: *
03: * Created on Jul 7, 2003
04: *
05: * $Id: RuntimeErrorFormatter.java 3124 2005-02-17 23:51:25Z gojomo $
06: *
07: * Copyright (C) 2003 Internet Archive.
08: *
09: * 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
52: .getObject(A_RUNTIME_EXCEPTION);
53: assert t != null : "Null throwable";
54: StringWriter sw = new StringWriter();
55: if (t == null) {
56: sw.write("No exception to report.");
57: } else {
58: t.printStackTrace(new PrintWriter(sw));
59: }
60: stackTrace = sw.toString();
61: }
62: }
63: return super .format(lr) + " " + stackTrace;
64: }
65: }
|