[ 
https://issues.apache.org/jira/browse/NUTCH-1078?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13113567#comment-13113567
 ] 

Lewis John McGibbney commented on NUTCH-1078:
---------------------------------------------

OK so this kinda opened up a couple of avenues. I am interested to see how we 
review and act on this one. Having discussed our problem with some slf4j users, 
the following seems to sum up the options.
----------------------------------
The problem has to do with how LogUtil is implemented.
Here are two possible solutions.

1) Get rid of the LogUtil class. For example, in HttpBase, instead of

{code}
 } catch (Throwable e) {
  e.printStackTrace(LogUtil.getErrorStream(logger));
  return new ProtocolOutput(null, new ProtocolStatus(e));
 }
{code}
 write instead
{code}
 } catch (Throwable e) {
  logger.error("Failed to get protocol output", e);

  return new ProtocolOutput(null, new ProtocolStatus(e));
 }
{code}
This latter form is the standard way of logging exceptions and this is the 
format some other Nutch code uses. I noticed this when I was creating the 
various patches. 
We would need to repeat the above operation in all places where LogUtil is 
used. There are about 60 such places located in about a dozen classes.

2) In LogUtil, replace
{code}
static {
 try {
  TRACE=Logger.class.getMethod("trace", new Class[] { Object.class });
  DEBUG=Logger.class.getMethod("debug", new Class[] { Object.class });
  INFO=Logger.class.getMethod("info",  new Class[] { Object.class });
 } catch ...
 }
}
{code}
with
{code}
static {
 try {
  TRACE=Logger.class.getMethod("trace", new Class[] {String.class});
  DEBUG=Logger.class.getMethod("debug", new Class[] {String.class});
  INFO=Logger.class.getMethod("info",  new Class[] {String.class});
 } catch ...
 }
}
{code}
On line 104 change
{code}
 method.invoke(logger, new Object[] {toString().trim() });
{code}
to
{code}
 method.invoke(logger, new String[] {toString().trim() });
{code}

Further to this, a suggestion was raised that unless there is a good reason not 
to, it might be an idea to get rid of LogUtil in from the Nutch code base 
altogether as it seems like a very convoluted way for logging exceptions. I 
(and the kind folks from slf4j who I spoke with) by no means understand every 
aspect of why we currently use LogUtil, therefore I really need some opinions 
from you guys to sort this one out. Thanks 

> Upgrade all instances of commons logging to slf4j (with log4j backend)
> ----------------------------------------------------------------------
>
>                 Key: NUTCH-1078
>                 URL: https://issues.apache.org/jira/browse/NUTCH-1078
>             Project: Nutch
>          Issue Type: Improvement
>    Affects Versions: 1.4
>            Reporter: Lewis John McGibbney
>            Assignee: Lewis John McGibbney
>            Priority: Minor
>             Fix For: 1.4
>
>         Attachments: NUTCH-1078-branch-1.4-20110816.patch, 
> NUTCH-1078-branch-1.4-20110824-v2.patch, 
> NUTCH-1078-branch-1.4-20110911-v3.patch, 
> NUTCH-1078-branch-1.4-20110916-v4.patch
>
>
> Whilst working on another issue, I noticed that some classes still import and 
> use commons logging for example HttpBase.java
> {code}
> import java.util.*;
> // Commons Logging imports
> import org.apache.commons.logging.Log;
> import org.apache.commons.logging.LogFactory;
> // Nutch imports
> import org.apache.nutch.crawl.CrawlDatum;
> {code}
> At this stage I am unsure how many (if any others) still import and reply 
> upon commons logging, however they should be upgraded to slf4j for branch-1.4.

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

Reply via email to