Return-Path: Delivered-To: apmail-lucene-nutch-dev-archive@www.apache.org Received: (qmail 33936 invoked from network); 5 Apr 2006 21:12:00 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 5 Apr 2006 21:12:00 -0000 Received: (qmail 79745 invoked by uid 500); 5 Apr 2006 21:12:00 -0000 Delivered-To: apmail-lucene-nutch-dev-archive@lucene.apache.org Received: (qmail 79338 invoked by uid 500); 5 Apr 2006 21:11:59 -0000 Mailing-List: contact nutch-dev-help@lucene.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: nutch-dev@lucene.apache.org Delivered-To: mailing list nutch-dev@lucene.apache.org Received: (qmail 79327 invoked by uid 99); 5 Apr 2006 21:11:59 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 05 Apr 2006 14:11:59 -0700 X-ASF-Spam-Status: No, hits=0.0 required=10.0 tests= X-Spam-Check-By: apache.org Received-SPF: pass (asf.osuosl.org: local policy) Received: from [216.23.125.30] (HELO mx.scriptall.com) (216.23.125.30) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 05 Apr 2006 14:11:58 -0700 Received: (qmail 26026 invoked by uid 512); 5 Apr 2006 17:11:50 -0400 Received: from cburkey@openedit.org by edison by uid 509 with qmail-scanner-1.22-st-qms (spamassassin: 2.63. Clear:RC:1(65.27.145.52):. Processed in 0.06646 secs); 05 Apr 2006 21:11:50 -0000 X-Antivirus-MYDOMAIN-Mail-From: cburkey@openedit.org via edison X-Antivirus-MYDOMAIN: 1.22-st-qms (Clear:RC:1(65.27.145.52):. Processed in 0.06646 secs Process 26020) Received: from cpe-65-27-145-52.cinci.res.rr.com (HELO [192.168.1.100]) (cburkey@openeditpro.com@65.27.145.52) by mx.scriptall.com with SMTP; Wed, 05 Apr 2006 17:11:49 -0400 Message-ID: <44343287.2070706@openedit.org> Date: Wed, 05 Apr 2006 17:11:35 -0400 From: Christopher Burkey User-Agent: Thunderbird 1.5 (X11/20051201) MIME-Version: 1.0 To: nutch-dev@lucene.apache.org Subject: Patch to remove Nutch formating from logs Content-Type: multipart/mixed; boundary="------------000100090904010105060205" X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N --------------000100090904010105060205 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Hello, Here is a patch to change org.apache.nutch.util.LogFormatter to not insert itself as the default handler for the system. I have been using Nutch for a year and have been waiting for a version that I can embed into OpenEdit. The problem has been that Nutch inserts itself as the formatter for the Java log system and that interferes with OpenEdit logging. -- 513-542-3401 cburkey@openedit.org http://www.openedit.org --------------000100090904010105060205 Content-Type: text/plain; name="logpatch.txt" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="logpatch.txt" diff -Naur ../java/org/apache/nutch/util/LogFormatter.java java/org/apache/nutch/util/LogFormatter.java --- ../java/org/apache/nutch/util/LogFormatter.java 2006-03-31 13:40:50.000000000 -0500 +++ java/org/apache/nutch/util/LogFormatter.java 2006-04-05 16:27:59.000000000 -0400 @@ -16,13 +16,23 @@ package org.apache.nutch.util; -import java.util.logging.*; -import java.io.*; -import java.text.*; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.PrintStream; +import java.io.PrintWriter; +import java.io.StringWriter; +import java.text.FieldPosition; +import java.text.SimpleDateFormat; import java.util.Date; - -/** Prints just the date and the log message. */ - +import java.util.logging.Formatter; +import java.util.logging.Level; +import java.util.logging.LogRecord; +import java.util.logging.Logger; + +/** Prints just the date and the log message. + * This was also used to stop processing as nutch crawls a web site + * cburkey@openedit.org changed this code to use a LogWrapper class to catch severe errors + * */ public class LogFormatter extends Formatter { private static final String FORMAT = "yyMMdd HHmmss"; private static final String NEWLINE = System.getProperty("line.separator"); @@ -35,20 +45,27 @@ private static boolean showTime = true; private static boolean showThreadIDs = false; + protected static LogFormatter sharedformatter = new LogFormatter(); + protected static SevereLogHandler sharedhandler = new SevereLogHandler(sharedformatter); + + /* // install when this class is loaded static { Handler[] handlers = LogFormatter.getLogger("").getHandlers(); for (int i = 0; i < handlers.length; i++) { - handlers[i].setFormatter(new LogFormatter()); + handlers[i].setFormatter(sharedformatter); handlers[i].setLevel(Level.FINEST); } } - + */ /** Gets a logger and, as a side effect, installs this as the default * formatter. */ public static Logger getLogger(String name) { // just referencing this class installs it - return Logger.getLogger(name); + Logger logr = Logger.getLogger(name); + logr.addHandler(sharedhandler); + + return logr; } /** When true, time is logged with each entry. */ @@ -60,7 +77,10 @@ public static void setShowThreadIDs(boolean showThreadIDs) { LogFormatter.showThreadIDs = showThreadIDs; } - + public void setLoggedSevere( boolean inSevere ) + { + loggedSevere = inSevere; + } /** * Format the given LogRecord. * @param record the log record to be formatted. diff -Naur ../java/org/apache/nutch/util/SevereLogHandler.java java/org/apache/nutch/util/SevereLogHandler.java --- ../java/org/apache/nutch/util/SevereLogHandler.java 1969-12-31 19:00:00.000000000 -0500 +++ java/org/apache/nutch/util/SevereLogHandler.java 2006-04-05 16:29:20.000000000 -0400 @@ -0,0 +1,46 @@ +/* + * Created on Apr 5, 2006 + */ +package org.apache.nutch.util; + +import java.util.logging.Handler; +import java.util.logging.Level; +import java.util.logging.LogRecord; + +public class SevereLogHandler extends Handler +{ + protected LogFormatter fieldNutchFormatter; + + public SevereLogHandler(LogFormatter inFormatter) + { + setNutchFormatter(inFormatter); + } + + protected LogFormatter getNutchFormatter() + { + return fieldNutchFormatter; + } + + protected void setNutchFormatter(LogFormatter inNutchFormatter) + { + fieldNutchFormatter = inNutchFormatter; + } + + public void publish(LogRecord inRecord) + { + if ( inRecord.getLevel().intValue() == Level.SEVERE.intValue()) + { + getNutchFormatter().setLoggedSevere(true); + } + } + + public void flush() + { + } + + public void close() throws SecurityException + { + } + + +} --------------000100090904010105060205--