Skip to content

armgit / nutch

Public Imported from GitHub
0

Apache Nutch is an extensible and scalable web crawler

NUTCH-309 : Added logging code guards

Jerome Charron86bf476a763c
diff --git a/src/java/org/apache/nutch/analysis/CommonGrams.java b/src/java/org/apache/nutch/analysis/CommonGrams.java
index cec8ec4d8..6b36b80c4 100644
--- a/src/java/org/apache/nutch/analysis/CommonGrams.java
+++ b/src/java/org/apache/nutch/analysis/CommonGrams.java
@@ -157,13 +157,17 @@ public class CommonGrams {
TokenStream ts = new NutchDocumentTokenizer(new StringReader(line));
Token token = ts.next();
if (token == null) {
- LOG.warn("Line does not contain a field name: " + line);
+ if (LOG.isWarnEnabled()) {
+ LOG.warn("Line does not contain a field name: " + line);
+ }
continue;
}
String field = token.termText();
token = ts.next();
if (token == null) {
- LOG.warn("Line contains only a field name, no word: " + line);
+ if (LOG.isWarnEnabled()) {
+ LOG.warn("Line contains only a field name, no word: " + line);
+ }
continue;
}
String gram = token.termText();
@@ -208,7 +212,10 @@ public class CommonGrams {
/** Optimizes phrase queries to use n-grams when possible. */
public String[] optimizePhrase(Phrase phrase, String field) {
- //LOG.info("Optimizing " + phrase + " for " + field);
+
+ if (LOG.isTraceEnabled()) {
+ LOG.trace("Optimizing " + phrase + " for " + field);
+ }
ArrayList result = new ArrayList();
TokenStream ts = getFilter(new ArrayTokens(phrase), field);
Token token, prev=null;
diff --git a/src/java/org/apache/nutch/clustering/OnlineClustererFactory.java b/src/java/org/apache/nutch/clustering/OnlineClustererFactory.java
index 4e14ae350..f1bad7ec1 100644
--- a/src/java/org/apache/nutch/clustering/OnlineClustererFactory.java
+++ b/src/java/org/apache/nutch/clustering/OnlineClustererFactory.java
@@ -76,18 +76,24 @@ public class OnlineClustererFactory {
if (extensionName != null) {
Extension extension = findExtension(extensionName);
if (extension != null) {
- LOG.info("Using clustering extension: " + extensionName);
+ if (LOG.isInfoEnabled()) {
+ LOG.info("Using clustering extension: " + extensionName);
+ }
return (OnlineClusterer) extension.getExtensionInstance();
}
- LOG.warn("Clustering extension not found: '" + extensionName
- + "', trying the default");
+ if (LOG.isWarnEnabled()) {
+ LOG.warn("Clustering extension not found: '" + extensionName +
+ "', trying the default");
+ }
// not found, fallback to the default, if available.
}
final Extension[] extensions = this.extensionPoint.getExtensions();
if (extensions.length > 0) {
- LOG.info("Using the first clustering extension found: "
- + extensions[0].getId());
+ if (LOG.isInfoEnabled()) {
+ LOG.info("Using the first clustering extension found: " +
+ extensions[0].getId());
+ }
return (OnlineClusterer) extensions[0].getExtensionInstance();
} else {
return null;
diff --git a/src/java/org/apache/nutch/crawl/Crawl.java b/src/java/org/apache/nutch/crawl/Crawl.java
index 07c217723..8b3591bdd 100644
--- a/src/java/org/apache/nutch/crawl/Crawl.java
+++ b/src/java/org/apache/nutch/crawl/Crawl.java
@@ -84,14 +84,15 @@ public class Crawl {
throw new RuntimeException(dir + " already exists.");
}
- LOG.info("crawl started in: " + dir);
- LOG.info("rootUrlDir = " + rootUrlDir);
- LOG.info("threads = " + threads);
- LOG.info("depth = " + depth);
-
- if (topN != Integer.MAX_VALUE)
- LOG.info("topN = " + topN);
-
+ if (LOG.isInfoEnabled()) {
+ LOG.info("crawl started in: " + dir);
+ LOG.info("rootUrlDir = " + rootUrlDir);
+ LOG.info("threads = " + threads);
+ LOG.info("depth = " + depth);
+ if (topN != Integer.MAX_VALUE)
+ LOG.info("topN = " + topN);
+ }
+
Path crawlDb = new Path(dir + "/crawldb");
Path linkDb = new Path(dir + "/linkdb");
Path segments = new Path(dir + "/segments");
@@ -121,6 +122,6 @@ public class Crawl {
new DeleteDuplicates(job).dedup(new Path[] { indexes });
new IndexMerger(fs, fs.listPaths(indexes), index, tmpDir, job).merge();
- LOG.info("crawl finished: " + dir);
+ if (LOG.isInfoEnabled()) { LOG.info("crawl finished: " + dir); }
}
}
diff --git a/src/java/org/apache/nutch/crawl/CrawlDb.java b/src/java/org/apache/nutch/crawl/CrawlDb.java
index 95ff12d11..704227425 100644
--- a/src/java/org/apache/nutch/crawl/CrawlDb.java
+++ b/src/java/org/apache/nutch/crawl/CrawlDb.java
@@ -45,19 +45,24 @@ public class CrawlDb extends Configured {
}
public void update(Path crawlDb, Path segment) throws IOException {
- LOG.info("CrawlDb update: starting");
- LOG.info("CrawlDb update: db: " + crawlDb);
- LOG.info("CrawlDb update: segment: " + segment);
+
+ if (LOG.isInfoEnabled()) {
+ LOG.info("CrawlDb update: starting");
+ LOG.info("CrawlDb update: db: " + crawlDb);
+ LOG.info("CrawlDb update: segment: " + segment);
+ }
JobConf job = CrawlDb.createJob(getConf(), crawlDb);
job.addInputPath(new Path(segment, CrawlDatum.FETCH_DIR_NAME));
job.addInputPath(new Path(segment, CrawlDatum.PARSE_DIR_NAME));
- LOG.info("CrawlDb update: Merging segment data into db.");
+ if (LOG.isInfoEnabled()) {
+ LOG.info("CrawlDb update: Merging segment data into db.");
+ }
JobClient.runJob(job);
CrawlDb.install(job, crawlDb);
- LOG.info("CrawlDb update: done");
+ if (LOG.isInfoEnabled()) { LOG.info("CrawlDb update: done"); }
}
public static JobConf createJob(Configuration config, Path crawlDb) {
diff --git a/src/java/org/apache/nutch/crawl/CrawlDbMerger.java b/src/java/org/apache/nutch/crawl/CrawlDbMerger.java
index 336e55208..75c34789e 100644
--- a/src/java/org/apache/nutch/crawl/CrawlDbMerger.java
+++ b/src/java/org/apache/nutch/crawl/CrawlDbMerger.java
@@ -70,7 +70,9 @@ public class CrawlDbMerger extends Configured {
if (filters.filter(((UTF8) key).toString()) == null)
return;
} catch (Exception e) {
- LOG.debug("Can't filter " + key + ": " + e);
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Can't filter " + key + ": " + e);
+ }
}
}
CrawlDatum res = null;
diff --git a/src/java/org/apache/nutch/crawl/CrawlDbReader.java b/src/java/org/apache/nutch/crawl/CrawlDbReader.java
index 64ccc5230..da6c070eb 100644
--- a/src/java/org/apache/nutch/crawl/CrawlDbReader.java
+++ b/src/java/org/apache/nutch/crawl/CrawlDbReader.java
@@ -205,7 +205,11 @@ public class CrawlDbReader implements Closeable {
}
public void processStatJob(String crawlDb, Configuration config) throws IOException {
- LOG.info("CrawlDb statistics start: " + crawlDb);
+
+ if (LOG.isInfoEnabled()) {
+ LOG.info("CrawlDb statistics start: " + crawlDb);
+ }
+
Path tmpFolder = new Path(crawlDb, "stat_tmp" + System.currentTimeMillis());
JobConf job = new NutchJob(config);
@@ -252,27 +256,30 @@ public class CrawlDbReader implements Closeable {
else if (k.startsWith("avg")) avg++;
}
}
- LOG.info("Statistics for CrawlDb: " + crawlDb);
- Iterator it = stats.keySet().iterator();
- while (it.hasNext()) {
- String k = (String) it.next();
- LongWritable val = (LongWritable) stats.get(k);
- if (k.indexOf("score") != -1) {
- if (k.startsWith("min")) {
- LOG.info(k + ":\t" + (float) ((float) (val.get() / min) / 1000.0f));
- } else if (k.startsWith("max")) {
- LOG.info(k + ":\t" + (float) ((float) (val.get() / max) / 1000.0f));
- } else if (k.startsWith("avg")) {
- LOG.info(k + ":\t" + (float) ((float) (val.get() / avg) / 1000.0f));
- }
- } else if (k.startsWith("status")) {
- int code = Integer.parseInt(k.substring(k.indexOf(' ') + 1));
- LOG.info(k + " (" + CrawlDatum.statNames[code] + "):\t" + val);
- } else LOG.info(k + ":\t" + val);
+
+ if (LOG.isInfoEnabled()) {
+ LOG.info("Statistics for CrawlDb: " + crawlDb);
+ Iterator it = stats.keySet().iterator();
+ while (it.hasNext()) {
+ String k = (String) it.next();
+ LongWritable val = (LongWritable) stats.get(k);
+ if (k.indexOf("score") != -1) {
+ if (k.startsWith("min")) {
+ LOG.info(k + ":\t" + (float) ((float) (val.get() / min) / 1000.0f));
+ } else if (k.startsWith("max")) {
+ LOG.info(k + ":\t" + (float) ((float) (val.get() / max) / 1000.0f));
+ } else if (k.startsWith("avg")) {
+ LOG.info(k + ":\t" + (float) ((float) (val.get() / avg) / 1000.0f));
+ }
+ } else if (k.startsWith("status")) {
+ int code = Integer.parseInt(k.substring(k.indexOf(' ') + 1));
+ LOG.info(k + " (" + CrawlDatum.statNames[code] + "):\t" + val);
+ } else LOG.info(k + ":\t" + val);
+ }
}
// removing the tmp folder
fileSystem.delete(tmpFolder);
- LOG.info("CrawlDb statistics: done");
+ if (LOG.isInfoEnabled()) { LOG.info("CrawlDb statistics: done"); }
}
@@ -296,8 +303,11 @@ public class CrawlDbReader implements Closeable {
public void processDumpJob(String crawlDb, String output, Configuration config) throws IOException {
- LOG.info("CrawlDb dump: starting");
- LOG.info("CrawlDb db: " + crawlDb);
+ if (LOG.isInfoEnabled()) {
+ LOG.info("CrawlDb dump: starting");
+ LOG.info("CrawlDb db: " + crawlDb);
+ }
+
Path outFolder = new Path(output);
JobConf job = new NutchJob(config);
@@ -314,12 +324,16 @@ public class CrawlDbReader implements Closeable {
job.setOutputValueClass(CrawlDatum.class);
JobClient.runJob(job);
- LOG.info("CrawlDb dump: done");
+ if (LOG.isInfoEnabled()) { LOG.info("CrawlDb dump: done"); }
}
public void processTopNJob(String crawlDb, long topN, float min, String output, Configuration config) throws IOException {
- LOG.info("CrawlDb topN: starting (topN=" + topN + ", min=" + min + ")");
- LOG.info("CrawlDb db: " + crawlDb);
+
+ if (LOG.isInfoEnabled()) {
+ LOG.info("CrawlDb topN: starting (topN=" + topN + ", min=" + min + ")");
+ LOG.info("CrawlDb db: " + crawlDb);
+ }
+
Path outFolder = new Path(output);
Path tempDir =
new Path(config.get("mapred.temp.dir", ".") +
@@ -343,7 +357,9 @@ public class CrawlDbReader implements Closeable {
job.setLong("CrawlDbReader.topN.min", Math.round(1000000.0 * min));
JobClient.runJob(job);
- LOG.info("CrawlDb topN: collecting topN scores.");
+ if (LOG.isInfoEnabled()) {
+ LOG.info("CrawlDb topN: collecting topN scores.");
+ }
job = new NutchJob(config);
job.setLong("CrawlDbReader.topN", topN);
@@ -365,7 +381,7 @@ public class CrawlDbReader implements Closeable {
JobClient.runJob(job);
FileSystem fs = FileSystem.get(config);
fs.delete(tempDir);
- LOG.info("CrawlDb topN: done");
+ if (LOG.isInfoEnabled()) { LOG.info("CrawlDb topN: done"); }
}
diff --git a/src/java/org/apache/nutch/crawl/CrawlDbReducer.java b/src/java/org/apache/nutch/crawl/CrawlDbReducer.java
index a4e5bca6d..0e2411ca8 100644
--- a/src/java/org/apache/nutch/crawl/CrawlDbReducer.java
+++ b/src/java/org/apache/nutch/crawl/CrawlDbReducer.java
@@ -108,8 +108,10 @@ public class CrawlDbReducer implements Reducer {
try {
scfilters.initialScore((UTF8)key, result);
} catch (ScoringFilterException e) {
- LOG.warn("Cannot filter init score for url " + key +
- ", using default: " + e.getMessage());
+ if (LOG.isWarnEnabled()) {
+ LOG.warn("Cannot filter init score for url " + key +
+ ", using default: " + e.getMessage());
+ }
result.setScore(scoreInjected);
}
}
@@ -122,7 +124,9 @@ public class CrawlDbReducer implements Reducer {
break;
case CrawlDatum.STATUS_SIGNATURE:
- LOG.warn("Lone CrawlDatum.STATUS_SIGNATURE: " + key);
+ if (LOG.isWarnEnabled()) {
+ LOG.warn("Lone CrawlDatum.STATUS_SIGNATURE: " + key);
+ }
return;
case CrawlDatum.STATUS_FETCH_RETRY: // temporary failure
if (old != null)
@@ -147,7 +151,9 @@ public class CrawlDbReducer implements Reducer {
try {
scfilters.updateDbScore((UTF8)key, result, linked);
} catch (Exception e) {
- LOG.warn("Couldn't update score, key=" + key + ": " + e);
+ if (LOG.isWarnEnabled()) {
+ LOG.warn("Couldn't update score, key=" + key + ": " + e);
+ }
}
output.collect(key, result);
}
diff --git a/src/java/org/apache/nutch/crawl/Generator.java b/src/java/org/apache/nutch/crawl/Generator.java
index f064cb8b4..b65523801 100644
--- a/src/java/org/apache/nutch/crawl/Generator.java
+++ b/src/java/org/apache/nutch/crawl/Generator.java
@@ -98,7 +98,9 @@ public class Generator extends Configured {
if (filters.filter(url.toString()) == null)
return;
} catch (URLFilterException e) {
- LOG.warn("Couldn't filter url: " + url + " (" + e.getMessage() + ")");
+ if (LOG.isWarnEnabled()) {
+ LOG.warn("Couldn't filter url: " + url + " (" + e.getMessage() + ")");
+ }
}
CrawlDatum crawlDatum = (CrawlDatum)value;
@@ -112,7 +114,9 @@ public class Generator extends Configured {
try {
sort = scfilters.generatorSortValue((UTF8)key, crawlDatum, sort);
} catch (ScoringFilterException sfe) {
- LOG.warn("Couldn't filter generatorSortValue for " + key + ": " + sfe);
+ if (LOG.isWarnEnabled()) {
+ LOG.warn("Couldn't filter generatorSortValue for " + key + ": " + sfe);
+ }
}
// sort by decreasing score
sortValue.set(sort);
@@ -150,9 +154,13 @@ public class Generator extends Configured {
InetAddress ia = InetAddress.getByName(host);
host = ia.getHostAddress();
} catch (UnknownHostException uhe) {
- LOG.debug("DNS lookup failed: " + host + ", skipping.");
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("DNS lookup failed: " + host + ", skipping.");
+ }
dnsFailure++;
- if (dnsFailure % 1000 == 0) LOG.warn("DNS failures: " + dnsFailure);
+ if ((dnsFailure % 1000 == 0) && (LOG.isWarnEnabled())) {
+ LOG.warn("DNS failures: " + dnsFailure);
+ }
continue;
}
}
@@ -168,8 +176,10 @@ public class Generator extends Configured {
// skip URL if above the limit per host.
if (hostCount.get() > maxPerHost) {
if (hostCount.get() == maxPerHost + 1) {
- LOG.info("Host "+ host +" has more than "+ maxPerHost +" URLs."+
- " Skipping additional.");
+ if (LOG.isInfoEnabled()) {
+ LOG.info("Host " + host + " has more than " + maxPerHost +
+ " URLs." + " Skipping additional.");
+ }
}
continue;
}
@@ -257,11 +267,13 @@ public class Generator extends Configured {
Path segment = new Path(segments, generateSegmentName());
Path output = new Path(segment, CrawlDatum.GENERATE_DIR_NAME);
- LOG.info("Generator: starting");
- LOG.info("Generator: segment: " + segment);
+ if (LOG.isInfoEnabled()) {
+ LOG.info("Generator: starting");
+ LOG.info("Generator: segment: " + segment);
+ LOG.info("Generator: Selecting most-linked urls due for fetch.");
+ }
// map to inverted subset due for fetch, sort by link count
- LOG.info("Generator: Selecting most-linked urls due for fetch.");
JobConf job = new NutchJob(getConf());
job.setJobName("generate: select " + segment);
@@ -288,7 +300,9 @@ public class Generator extends Configured {
JobClient.runJob(job);
// invert again, paritition by host, sort by url hash
- LOG.info("Generator: Partitioning selected urls by host, for politeness.");
+ if (LOG.isInfoEnabled()) {
+ LOG.info("Generator: Partitioning selected urls by host, for politeness.");
+ }
job = new NutchJob(getConf());
job.setJobName("generate: partition " + segment);
@@ -312,7 +326,7 @@ public class Generator extends Configured {
new JobClient(getConf()).getFs().delete(tempDir);
- LOG.info("Generator: done.");
+ if (LOG.isInfoEnabled()) { LOG.info("Generator: done."); }
return segment;
}
@@ -355,8 +369,9 @@ public class Generator extends Configured {
}
}
- if (topN != Long.MAX_VALUE)
+ if ((LOG.isInfoEnabled()) && (topN != Long.MAX_VALUE)) {
LOG.info("topN: " + topN);
+ }
Generator gen = new Generator(NutchConfiguration.create());
gen.generate(dbDir, segmentsDir, numFetchers, topN, curTime);
}
diff --git a/src/java/org/apache/nutch/crawl/Injector.java b/src/java/org/apache/nutch/crawl/Injector.java
index 3050c1f85..b8c9d2ea3 100644
--- a/src/java/org/apache/nutch/crawl/Injector.java
+++ b/src/java/org/apache/nutch/crawl/Injector.java
@@ -70,7 +70,7 @@ public class Injector extends Configured {
url = urlNormalizer.normalize(url); // normalize the url
url = filters.filter(url); // filter the url
} catch (Exception e) {
- LOG.warn("Skipping " +url+":"+e);
+ if (LOG.isWarnEnabled()) { LOG.warn("Skipping " +url+":"+e); }
url = null;
}
if (url != null) { // if it passes
@@ -80,8 +80,10 @@ public class Injector extends Configured {
try {
scfilters.initialScore(value, datum);
} catch (ScoringFilterException e) {
- LOG.warn("Cannot filter init score for url " + url +
- ", using default (" + e.getMessage() + ")");
+ if (LOG.isWarnEnabled()) {
+ LOG.warn("Cannot filter init score for url " + url +
+ ", using default (" + e.getMessage() + ")");
+ }
datum.setScore(scoreInjected);
}
output.collect(value, datum);
@@ -107,9 +109,12 @@ public class Injector extends Configured {
}
public void inject(Path crawlDb, Path urlDir) throws IOException {
- LOG.info("Injector: starting");
- LOG.info("Injector: crawlDb: " + crawlDb);
- LOG.info("Injector: urlDir: " + urlDir);
+
+ if (LOG.isInfoEnabled()) {
+ LOG.info("Injector: starting");
+ LOG.info("Injector: crawlDb: " + crawlDb);
+ LOG.info("Injector: urlDir: " + urlDir);
+ }
Path tempDir =
new Path(getConf().get("mapred.temp.dir", ".") +
@@ -117,7 +122,9 @@ public class Injector extends Configured {
Integer.toString(new Random().nextInt(Integer.MAX_VALUE)));
// map text input file to a <url,CrawlDatum> file
- LOG.info("Injector: Converting injected urls to crawl db entries.");
+ if (LOG.isInfoEnabled()) {
+ LOG.info("Injector: Converting injected urls to crawl db entries.");
+ }
JobConf sortJob = new NutchJob(getConf());
sortJob.setJobName("inject " + urlDir);
sortJob.setInputPath(urlDir);
@@ -131,7 +138,9 @@ public class Injector extends Configured {
JobClient.runJob(sortJob);
// merge with existing crawl db
- LOG.info("Injector: Merging injected urls into crawl db.");
+ if (LOG.isInfoEnabled()) {
+ LOG.info("Injector: Merging injected urls into crawl db.");
+ }
JobConf mergeJob = CrawlDb.createJob(getConf(), crawlDb);
mergeJob.addInputPath(tempDir);
JobClient.runJob(mergeJob);
@@ -140,7 +149,7 @@ public class Injector extends Configured {
// clean up
FileSystem fs = new JobClient(getConf()).getFs();
fs.delete(tempDir);
- LOG.info("Injector: done");
+ if (LOG.isInfoEnabled()) { LOG.info("Injector: done"); }
}
diff --git a/src/java/org/apache/nutch/crawl/LinkDb.java b/src/java/org/apache/nutch/crawl/LinkDb.java
index e77d7293d..4b7db651f 100644
--- a/src/java/org/apache/nutch/crawl/LinkDb.java
+++ b/src/java/org/apache/nutch/crawl/LinkDb.java
@@ -64,7 +64,9 @@ public class LinkDb extends Configured implements Mapper, Reducer {
if (filters.filter(((UTF8)key).toString()) == null)
return;
} catch (Exception e) {
- LOG.debug("Can't filter " + key + ": " + e);
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Can't filter " + key + ": " + e);
+ }
}
}
Inlinks inlinks = null;
@@ -85,7 +87,9 @@ public class LinkDb extends Configured implements Mapper, Reducer {
if (filters.filter(in.getFromUrl()) == null)
continue;
} catch (Exception e) {
- LOG.debug("Can't filter " + key + ": " + e);
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Can't filter " + key + ": " + e);
+ }
}
}
inlinks.add(in);
@@ -193,17 +197,24 @@ public class LinkDb extends Configured implements Mapper, Reducer {
}
public void invert(Path linkDb, Path[] segments) throws IOException {
- LOG.info("LinkDb: starting");
- LOG.info("LinkDb: linkdb: " + linkDb);
+
+ if (LOG.isInfoEnabled()) {
+ LOG.info("LinkDb: starting");
+ LOG.info("LinkDb: linkdb: " + linkDb);
+ }
JobConf job = LinkDb.createJob(getConf(), linkDb);
for (int i = 0; i < segments.length; i++) {
- LOG.info("LinkDb: adding segment: " + segments[i]);
+ if (LOG.isInfoEnabled()) {
+ LOG.info("LinkDb: adding segment: " + segments[i]);
+ }
job.addInputPath(new Path(segments[i], ParseData.DIR_NAME));
}
JobClient.runJob(job);
FileSystem fs = FileSystem.get(getConf());
if (fs.exists(linkDb)) {
- LOG.info("LinkDb: merging with existing linkdb: " + linkDb);
+ if (LOG.isInfoEnabled()) {
+ LOG.info("LinkDb: merging with existing linkdb: " + linkDb);
+ }
// try to merge
Path newLinkDb = job.getOutputPath();
job = LinkDb.createMergeJob(getConf(), linkDb);
@@ -213,7 +224,7 @@ public class LinkDb extends Configured implements Mapper, Reducer {
fs.delete(newLinkDb);
}
LinkDb.install(job, linkDb);
- LOG.info("LinkDb: done");
+ if (LOG.isInfoEnabled()) { LOG.info("LinkDb: done"); }
}
private static JobConf createJob(Configuration config, Path linkDb) {
diff --git a/src/java/org/apache/nutch/crawl/LinkDbReader.java b/src/java/org/apache/nutch/crawl/LinkDbReader.java
index 2e6219642..baf2e07e0 100644
--- a/src/java/org/apache/nutch/crawl/LinkDbReader.java
+++ b/src/java/org/apache/nutch/crawl/LinkDbReader.java
@@ -79,8 +79,11 @@ public class LinkDbReader implements Closeable {
}
public static void processDumpJob(String linkdb, String output, Configuration config) throws IOException {
- LOG.info("LinkDb dump: starting");
- LOG.info("LinkDb db: " + linkdb);
+
+ if (LOG.isInfoEnabled()) {
+ LOG.info("LinkDb dump: starting");
+ LOG.info("LinkDb db: " + linkdb);
+ }
Path outFolder = new Path(output);
JobConf job = new NutchJob(config);
diff --git a/src/java/org/apache/nutch/crawl/MapWritable.java b/src/java/org/apache/nutch/crawl/MapWritable.java
index 3fa063906..f59eaf470 100644
--- a/src/java/org/apache/nutch/crawl/MapWritable.java
+++ b/src/java/org/apache/nutch/crawl/MapWritable.java
@@ -313,7 +313,9 @@ public class MapWritable implements Writable {
clazz = Class.forName(UTF8.readString(in));
addIdEntry(id, clazz);
} catch (Exception e) {
- LOG.warn("MapWritable: unable to load internal map entry" + e.toString());
+ if (LOG.isWarnEnabled()) {
+ LOG.warn("Unable to load internal map entry" + e.toString());
+ }
fIdCount--;
}
}
@@ -329,8 +331,10 @@ public class MapWritable implements Writable {
fLast = fLast.fNextEntry = entry;
}
} catch (IOException e) {
- LOG.warn("MapWritable: unable to load meta data entry, ignoring.. : "
- + e.toString());
+ if (LOG.isWarnEnabled()) {
+ LOG.warn("Unable to load meta data entry, ignoring.. : " +
+ e.toString());
+ }
fSize--;
}
}
diff --git a/src/java/org/apache/nutch/crawl/SignatureFactory.java b/src/java/org/apache/nutch/crawl/SignatureFactory.java
index ecbe70e1a..3459d9eba 100644
--- a/src/java/org/apache/nutch/crawl/SignatureFactory.java
+++ b/src/java/org/apache/nutch/crawl/SignatureFactory.java
@@ -41,7 +41,9 @@ public class SignatureFactory {
Signature impl = (Signature)conf.getObject(clazz);
if (impl == null) {
try {
- LOG.info("Using Signature impl: " + clazz);
+ if (LOG.isInfoEnabled()) {
+ LOG.info("Using Signature impl: " + clazz);
+ }
Class implClass = Class.forName(clazz);
impl = (Signature)implClass.newInstance();
impl.setConf(conf);
diff --git a/src/java/org/apache/nutch/fetcher/Fetcher.java b/src/java/org/apache/nutch/fetcher/Fetcher.java
index ad7c859de..f5b7d7a37 100644
--- a/src/java/org/apache/nutch/fetcher/Fetcher.java
+++ b/src/java/org/apache/nutch/fetcher/Fetcher.java
@@ -115,8 +115,10 @@ public class Fetcher extends Configured implements MapRunnable {
break; // at eof, exit
}
} catch (IOException e) {
- e.printStackTrace(LogUtil.getFatalStream(LOG));
- LOG.fatal("fetcher caught:"+e.toString());
+ if (LOG.isFatalEnabled()) {
+ e.printStackTrace(LogUtil.getFatalStream(LOG));
+ LOG.fatal("fetcher caught:"+e.toString());
+ }
break;
}
@@ -128,13 +130,16 @@ public class Fetcher extends Configured implements MapRunnable {
UTF8 url = new UTF8();
url.set(key);
try {
- LOG.info("fetching " + url); // fetch the page
-
+ if (LOG.isInfoEnabled()) { LOG.info("fetching " + url); }
+
+ // fetch the page
boolean redirecting;
int redirectCount = 0;
do {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("redirectCount=" + redirectCount);
+ }
redirecting = false;
- LOG.debug("redirectCount=" + redirectCount);
Protocol protocol = this.protocolFactory.getProtocol(url.toString());
ProtocolOutput output = protocol.getProtocolOutput(url, datum);
ProtocolStatus status = output.getStatus();
@@ -155,8 +160,10 @@ public class Fetcher extends Configured implements MapRunnable {
url = new UTF8(newUrl);
redirecting = true;
redirectCount++;
- LOG.debug(" - content redirect to " + url);
- } else {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug(" - content redirect to " + url);
+ }
+ } else if (LOG.isDebugEnabled()) {
LOG.debug(" - content redirect skipped: " +
(newUrl != null ? "to same url" : "filtered"));
}
@@ -172,8 +179,10 @@ public class Fetcher extends Configured implements MapRunnable {
url = new UTF8(newUrl);
redirecting = true;
redirectCount++;
- LOG.debug(" - protocol redirect to " + url);
- } else {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug(" - protocol redirect to " + url);
+ }
+ } else if (LOG.isDebugEnabled()) {
LOG.debug(" - protocol redirect skipped: " +
(newUrl != null ? "to same url" : "filtered"));
}
@@ -195,12 +204,16 @@ public class Fetcher extends Configured implements MapRunnable {
break;
default:
- LOG.warn("Unknown ProtocolStatus: " + status.getCode());
+ if (LOG.isWarnEnabled()) {
+ LOG.warn("Unknown ProtocolStatus: " + status.getCode());
+ }
output(url, datum, null, CrawlDatum.STATUS_FETCH_GONE);
}
if (redirecting && redirectCount >= maxRedirect) {
- LOG.info(" - redirect count exceeded " + url);
+ if (LOG.isInfoEnabled()) {
+ LOG.info(" - redirect count exceeded " + url);
+ }
output(url, datum, null, CrawlDatum.STATUS_FETCH_GONE);
}
@@ -215,15 +228,19 @@ public class Fetcher extends Configured implements MapRunnable {
}
} catch (Throwable e) {
- e.printStackTrace(LogUtil.getFatalStream(LOG));
- LOG.fatal("fetcher caught:"+e.toString());
+ if (LOG.isFatalEnabled()) {
+ e.printStackTrace(LogUtil.getFatalStream(LOG));
+ LOG.fatal("fetcher caught:"+e.toString());
+ }
} finally {
synchronized (Fetcher.this) {activeThreads--;} // count threads
}
}
private void logError(UTF8 url, String message) {
- LOG.info("fetch of " + url + " failed with: " + message);
+ if (LOG.isInfoEnabled()) {
+ LOG.info("fetch of " + url + " failed with: " + message);
+ }
synchronized (Fetcher.this) { // record failure
errors++;
}
@@ -246,8 +263,10 @@ public class Fetcher extends Configured implements MapRunnable {
try {
scfilters.passScoreBeforeParsing(key, datum, content);
} catch (Exception e) {
- e.printStackTrace(LogUtil.getWarnStream(LOG));
- LOG.warn("Couldn't pass score, url " + key + " (" + e + ")");
+ if (LOG.isWarnEnabled()) {
+ e.printStackTrace(LogUtil.getWarnStream(LOG));
+ LOG.warn("Couldn't pass score, url " + key + " (" + e + ")");
+ }
}
Parse parse = null;
@@ -260,7 +279,9 @@ public class Fetcher extends Configured implements MapRunnable {
parseStatus = new ParseStatus(e);
}
if (!parseStatus.isSuccess()) {
- LOG.warn("Error parsing: " + key + ": " + parseStatus);
+ if (LOG.isWarnEnabled()) {
+ LOG.warn("Error parsing: " + key + ": " + parseStatus);
+ }
parse = parseStatus.getEmptyParse(getConf());
}
// Calculate page signature. For non-parsing fetchers this will
@@ -274,8 +295,10 @@ public class Fetcher extends Configured implements MapRunnable {
try {
scfilters.passScoreAfterParsing(key, content, parse);
} catch (Exception e) {
- e.printStackTrace(LogUtil.getWarnStream(LOG));
- LOG.warn("Couldn't pass score, url " + key + " (" + e + ")");
+ if (LOG.isWarnEnabled()) {
+ e.printStackTrace(LogUtil.getWarnStream(LOG));
+ LOG.warn("Couldn't pass score, url " + key + " (" + e + ")");
+ }
}
}
@@ -287,8 +310,10 @@ public class Fetcher extends Configured implements MapRunnable {
storingContent ? content : null,
parse != null ? new ParseImpl(parse) : null));
} catch (IOException e) {
- e.printStackTrace(LogUtil.getFatalStream(LOG));
- LOG.fatal("fetcher caught:"+e.toString());
+ if (LOG.isFatalEnabled()) {
+ e.printStackTrace(LogUtil.getFatalStream(LOG));
+ LOG.fatal("fetcher caught:"+e.toString());
+ }
}
if (parse != null) return parse.getData().getStatus();
else return null;
@@ -349,7 +374,7 @@ public class Fetcher extends Configured implements MapRunnable {
this.maxRedirect = getConf().getInt("http.redirect.max", 3);
int threadCount = getConf().getInt("fetcher.threads.fetch", 10);
- LOG.info("Fetcher: threads: " + threadCount);
+ if (LOG.isInfoEnabled()) { LOG.info("Fetcher: threads: " + threadCount); }
for (int i = 0; i < threadCount; i++) { // spawn threads
new FetcherThread(getConf()).start();
@@ -367,8 +392,10 @@ public class Fetcher extends Configured implements MapRunnable {
// some requests seem to hang, despite all intentions
synchronized (this) {
- if ((System.currentTimeMillis() - lastRequestStart) > timeout) {
- LOG.warn("Aborting with "+activeThreads+" hung threads.");
+ if ((System.currentTimeMillis() - lastRequestStart) > timeout) {
+ if (LOG.isWarnEnabled()) {
+ LOG.warn("Aborting with "+activeThreads+" hung threads.");
+ }
return;
}
}
@@ -380,8 +407,10 @@ public class Fetcher extends Configured implements MapRunnable {
public void fetch(Path segment, int threads, boolean parsing)
throws IOException {
- LOG.info("Fetcher: starting");
- LOG.info("Fetcher: segment: " + segment);
+ if (LOG.isInfoEnabled()) {
+ LOG.info("Fetcher: starting");
+ LOG.info("Fetcher: segment: " + segment);
+ }
JobConf job = new NutchJob(getConf());
job.setJobName("fetch " + segment);
@@ -406,7 +435,7 @@ public class Fetcher extends Configured implements MapRunnable {
job.setOutputValueClass(FetcherOutput.class);
JobClient.runJob(job);
- LOG.info("Fetcher: done");
+ if (LOG.isInfoEnabled()) { LOG.info("Fetcher: done"); }
}
diff --git a/src/java/org/apache/nutch/indexer/DeleteDuplicates.java b/src/java/org/apache/nutch/indexer/DeleteDuplicates.java
index 40a9c8d2a..d4af4cbe4 100644
--- a/src/java/org/apache/nutch/indexer/DeleteDuplicates.java
+++ b/src/java/org/apache/nutch/indexer/DeleteDuplicates.java
@@ -291,7 +291,7 @@ public class DeleteDuplicates extends Configured
public void dedup(Path[] indexDirs)
throws IOException {
- LOG.info("Dedup: starting");
+ if (LOG.isInfoEnabled()) { LOG.info("Dedup: starting"); }
Path hashDir =
new Path("dedup-hash-"+
@@ -300,7 +300,9 @@ public class DeleteDuplicates extends Configured
JobConf job = new NutchJob(getConf());
for (int i = 0; i < indexDirs.length; i++) {
- LOG.info("Dedup: adding indexes in: " + indexDirs[i]);
+ if (LOG.isInfoEnabled()) {
+ LOG.info("Dedup: adding indexes in: " + indexDirs[i]);
+ }
job.addInputPath(indexDirs[i]);
}
job.setJobName("dedup phase 1");
@@ -342,7 +344,7 @@ public class DeleteDuplicates extends Configured
new JobClient(getConf()).getFs().delete(hashDir);
- LOG.info("Dedup: done");
+ if (LOG.isInfoEnabled()) { LOG.info("Dedup: done"); }
}
public static void main(String[] args) throws Exception {
diff --git a/src/java/org/apache/nutch/indexer/IndexMerger.java b/src/java/org/apache/nutch/indexer/IndexMerger.java
index 02a34d44e..ff3fc6dc6 100644
--- a/src/java/org/apache/nutch/indexer/IndexMerger.java
+++ b/src/java/org/apache/nutch/indexer/IndexMerger.java
@@ -75,7 +75,7 @@ public class IndexMerger {
Directory[] dirs = new Directory[indexes.length];
for (int i = 0; i < indexes.length; i++) {
- LOG.info("Adding " + indexes[i]);
+ if (LOG.isInfoEnabled()) { LOG.info("Adding " + indexes[i]); }
dirs[i] = new FsDirectory(fs, indexes[i], false, this.conf);
}
@@ -136,7 +136,9 @@ public class IndexMerger {
//
// Merge the indices
//
- LOG.info("merging indexes to: " + outputIndex);
+ if (LOG.isInfoEnabled()) {
+ LOG.info("merging indexes to: " + outputIndex);
+ }
Path[] indexFiles = (Path[])indexDirs.toArray(new Path[indexDirs.size()]);
@@ -148,7 +150,7 @@ public class IndexMerger {
IndexMerger merger =
new IndexMerger(fs, indexFiles, outputIndex, workDir, conf);
merger.merge();
- LOG.info("done merging");
+ if (LOG.isInfoEnabled()) { LOG.info("done merging"); }
localFs.delete(workDir);
}
}
diff --git a/src/java/org/apache/nutch/indexer/Indexer.java b/src/java/org/apache/nutch/indexer/Indexer.java
index 3beae5cdc..3b206c565 100644
--- a/src/java/org/apache/nutch/indexer/Indexer.java
+++ b/src/java/org/apache/nutch/indexer/Indexer.java
@@ -108,9 +108,11 @@ public class Indexer extends Configured implements Reducer {
throws IOException { // unwrap & index doc
Document doc = (Document)((ObjectWritable)value).get();
NutchAnalyzer analyzer = factory.get(doc.get("lang"));
- LOG.info(" Indexing [" + doc.getField("url").stringValue() + "]" +
- " with analyzer " + analyzer +
- " (" + doc.get("lang") + ")");
+ if (LOG.isInfoEnabled()) {
+ LOG.info(" Indexing [" + doc.getField("url").stringValue() + "]" +
+ " with analyzer " + analyzer +
+ " (" + doc.get("lang") + ")");
+ }
writer.addDocument(doc, analyzer);
}
@@ -130,7 +132,8 @@ public class Indexer extends Configured implements Reducer {
try {
prog.start();
- LOG.info("Optimizing index."); // optimize & close index
+ if (LOG.isInfoEnabled()) { LOG.info("Optimizing index."); }
+ // optimize & close index
writer.optimize();
writer.close();
fs.completeLocalOutput(perm, temp); // copy to dfs
@@ -195,7 +198,7 @@ public class Indexer extends Configured implements Reducer {
parseData = (ParseData)value;
} else if (value instanceof ParseText) {
parseText = (ParseText)value;
- } else {
+ } else if (LOG.isWarnEnabled()) {
LOG.warn("Unrecognized type: "+value.getClass());
}
}
@@ -216,11 +219,13 @@ public class Indexer extends Configured implements Reducer {
doc.add(new Field("digest", metadata.get(Fetcher.SIGNATURE_KEY),
Field.Store.YES, Field.Index.NO));
-// LOG.info("Url: "+key.toString());
-// LOG.info("Title: "+parseData.getTitle());
-// LOG.info(crawlDatum.toString());
-// if (inlinks != null) {
-// LOG.info(inlinks.toString());
+// if (LOG.isInfoEnabled()) {
+// LOG.info("Url: "+key.toString());
+// LOG.info("Title: "+parseData.getTitle());
+// LOG.info(crawlDatum.toString());
+// if (inlinks != null) {
+// LOG.info(inlinks.toString());
+// }
// }
Parse parse = new ParseImpl(parseText, parseData);
@@ -228,7 +233,7 @@ public class Indexer extends Configured implements Reducer {
// run indexing filters
doc = this.filters.filter(doc, parse, (UTF8)key, fetchDatum, inlinks);
} catch (IndexingException e) {
- LOG.warn("Error indexing "+key+": "+e);
+ if (LOG.isWarnEnabled()) { LOG.warn("Error indexing "+key+": "+e); }
return;
}
@@ -238,7 +243,9 @@ public class Indexer extends Configured implements Reducer {
boost = this.scfilters.indexerScore((UTF8)key, doc, dbDatum,
fetchDatum, parse, inlinks, boost);
} catch (ScoringFilterException e) {
- LOG.warn("Error calculating score " + key + ": " + e);
+ if (LOG.isWarnEnabled()) {
+ LOG.warn("Error calculating score " + key + ": " + e);
+ }
return;
}
// apply boost to all indexed fields.
@@ -253,14 +260,18 @@ public class Indexer extends Configured implements Reducer {
public void index(Path indexDir, Path crawlDb, Path linkDb, Path[] segments)
throws IOException {
- LOG.info("Indexer: starting");
- LOG.info("Indexer: linkdb: " + linkDb);
+ if (LOG.isInfoEnabled()) {
+ LOG.info("Indexer: starting");
+ LOG.info("Indexer: linkdb: " + linkDb);
+ }
JobConf job = new NutchJob(getConf());
job.setJobName("index " + indexDir);
for (int i = 0; i < segments.length; i++) {
- LOG.info("Indexer: adding segment: " + segments[i]);
+ if (LOG.isInfoEnabled()) {
+ LOG.info("Indexer: adding segment: " + segments[i]);
+ }
job.addInputPath(new Path(segments[i], CrawlDatum.FETCH_DIR_NAME));
job.addInputPath(new Path(segments[i], ParseData.DIR_NAME));
job.addInputPath(new Path(segments[i], ParseText.DIR_NAME));
@@ -282,7 +293,7 @@ public class Indexer extends Configured implements Reducer {
job.setOutputValueClass(ObjectWritable.class);
JobClient.runJob(job);
- LOG.info("Indexer: done");
+ if (LOG.isInfoEnabled()) { LOG.info("Indexer: done"); }
}
public static void main(String[] args) throws Exception {
diff --git a/src/java/org/apache/nutch/indexer/IndexingFilters.java b/src/java/org/apache/nutch/indexer/IndexingFilters.java
index e12aa3016..bc4777b8d 100644
--- a/src/java/org/apache/nutch/indexer/IndexingFilters.java
+++ b/src/java/org/apache/nutch/indexer/IndexingFilters.java
@@ -50,7 +50,9 @@ public class IndexingFilters {
for (int i = 0; i < extensions.length; i++) {
Extension extension = extensions[i];
IndexingFilter filter = (IndexingFilter) extension.getExtensionInstance();
- LOG.info("Adding " + filter.getClass().getName());
+ if (LOG.isInfoEnabled()) {
+ LOG.info("Adding " + filter.getClass().getName());
+ }
if (!filterMap.containsKey(filter.getClass().getName())) {
filterMap.put(filter.getClass().getName(), filter);
}
diff --git a/src/java/org/apache/nutch/net/RegexUrlNormalizer.java b/src/java/org/apache/nutch/net/RegexUrlNormalizer.java
index df7d3e864..66d1a9353 100644
--- a/src/java/org/apache/nutch/net/RegexUrlNormalizer.java
+++ b/src/java/org/apache/nutch/net/RegexUrlNormalizer.java
@@ -99,22 +99,25 @@ public class RegexUrlNormalizer extends BasicUrlNormalizer
List rules=new ArrayList();
try {
- LOG.info("loading " + filename);
+ if (LOG.isInfoEnabled()) { LOG.info("loading " + filename); }
// borrowed heavily from code in Configuration.java
Document doc =
DocumentBuilderFactory.newInstance().newDocumentBuilder()
.parse(filename);
Element root = doc.getDocumentElement();
- if (!"regex-normalize".equals(root.getTagName()))
+ if ((!"regex-normalize".equals(root.getTagName())) &&
+ (LOG.isFatalEnabled())) {
LOG.fatal("bad conf file: top-level element not <regex-normalize>");
+ }
NodeList regexes = root.getChildNodes();
for (int i = 0; i < regexes.getLength(); i++) {
Node regexNode = regexes.item(i);
if (!(regexNode instanceof Element))
continue;
Element regex = (Element)regexNode;
- if (!"regex".equals(regex.getTagName()))
+ if ((!"regex".equals(regex.getTagName())) && (LOG.isWarnEnabled())) {
LOG.warn("bad conf file: element not <regex>");
+ }
NodeList fields = regex.getChildNodes();
String patternValue = null;
String subValue = null;
@@ -139,7 +142,9 @@ public class RegexUrlNormalizer extends BasicUrlNormalizer
}
} catch (Exception e) {
- LOG.fatal("error parsing " + filename +" conf file: " + e);
+ if (LOG.isFatalEnabled()) {
+ LOG.fatal("error parsing " + filename +" conf file: " + e);
+ }
}
return rules;
}
diff --git a/src/java/org/apache/nutch/net/UrlNormalizerFactory.java b/src/java/org/apache/nutch/net/UrlNormalizerFactory.java
index b2b72b8d7..2e5de54d9 100644
--- a/src/java/org/apache/nutch/net/UrlNormalizerFactory.java
+++ b/src/java/org/apache/nutch/net/UrlNormalizerFactory.java
@@ -41,7 +41,9 @@ public class UrlNormalizerFactory {
if (normalizer == null) {
try {
urlNormalizer = this.conf.get("urlnormalizer.class");
- LOG.info("Using URL normalizer: " + urlNormalizer);
+ if (LOG.isInfoEnabled()) {
+ LOG.info("Using URL normalizer: " + urlNormalizer);
+ }
Class normalizerClass = Class.forName(urlNormalizer);
normalizer = (UrlNormalizer) normalizerClass.newInstance();
normalizer.setConf(this.conf);
diff --git a/src/java/org/apache/nutch/ontology/OntologyFactory.java b/src/java/org/apache/nutch/ontology/OntologyFactory.java
index 12e81df4c..253969508 100644
--- a/src/java/org/apache/nutch/ontology/OntologyFactory.java
+++ b/src/java/org/apache/nutch/ontology/OntologyFactory.java
@@ -58,18 +58,24 @@ public class OntologyFactory {
if (extensionName != null) {
Extension extension = findExtension(extensionName);
if (extension != null) {
- LOG.info("Using ontology extension: " + extensionName);
+ if (LOG.isInfoEnabled()) {
+ LOG.info("Using ontology extension: " + extensionName);
+ }
return (Ontology) extension.getExtensionInstance();
}
- LOG.warn("Ontology extension not found: '" + extensionName
- + "', trying the default");
+ if (LOG.isWarnEnabled()) {
+ LOG.warn("Ontology extension not found: '" + extensionName +
+ "', trying the default");
+ }
// not found, fallback to the default, if available.
}
Extension[] extensions = this.extensionPoint.getExtensions();
if (extensions.length > 0) {
- LOG.info("Using the first ontology extension found: "
- + extensions[0].getId());
+ if (LOG.isInfoEnabled()) {
+ LOG.info("Using the first ontology extension found: " +
+ extensions[0].getId());
+ }
return (Ontology) extensions[0].getExtensionInstance();
} else {
return null;
diff --git a/src/java/org/apache/nutch/parse/OutlinkExtractor.java b/src/java/org/apache/nutch/parse/OutlinkExtractor.java
index e265a2217..b5ea7a87b 100644
--- a/src/java/org/apache/nutch/parse/OutlinkExtractor.java
+++ b/src/java/org/apache/nutch/parse/OutlinkExtractor.java
@@ -101,7 +101,9 @@ public class OutlinkExtractor {
// (SHOULD really check cpu time used so that heavily loaded systems
// do not unnecessarily hit this limit.)
if (System.currentTimeMillis() - start >= 60000L) {
- LOG.warn("Time limit exceeded for getOutLinks");
+ if (LOG.isWarnEnabled()) {
+ LOG.warn("Time limit exceeded for getOutLinks");
+ }
break;
}
result = matcher.getMatch();
@@ -110,7 +112,7 @@ public class OutlinkExtractor {
}
} catch (Exception ex) {
// if the matcher fails (perhaps a malformed URL) we just log it and move on
- LOG.error("getOutlinks", ex);
+ if (LOG.isErrorEnabled()) { LOG.error("getOutlinks", ex); }
}
final Outlink[] retval;
@@ -152,7 +154,9 @@ public class OutlinkExtractor {
//
// url = re.getParen(0);
//
- // LOG.trace("Extracted url: " + url);
+ // if (LOG.isTraceEnabled()) {
+ // LOG.trace("Extracted url: " + url);
+ // }
//
// try {
//
@@ -162,7 +166,7 @@ public class OutlinkExtractor {
// } catch (MalformedURLException ex) {
// // if it is a malformed URL we just throw it away and continue with
// // extraction.
- // LOG.error("getOutlinks", ex);
+ // if (LOG.isErrorEnabled()) { LOG.error("getOutlinks", ex); }
// }
//
// pos = re.getParenEnd(0);
@@ -215,7 +219,7 @@ public class OutlinkExtractor {
// } catch (MalformedURLException ex) {
// // if it is a malformed URL we just throw it away and continue with
// // extraction.
- // LOG.error("getOutlinks", ex);
+ // if (LOG.isErrorEnabled()) { LOG.error("getOutlinks", ex); }
// }
//
// pos = re.getParenEnd(0);
diff --git a/src/java/org/apache/nutch/parse/ParseOutputFormat.java b/src/java/org/apache/nutch/parse/ParseOutputFormat.java
index a225997d4..d61d7b07a 100644
--- a/src/java/org/apache/nutch/parse/ParseOutputFormat.java
+++ b/src/java/org/apache/nutch/parse/ParseOutputFormat.java
@@ -119,8 +119,10 @@ public class ParseOutputFormat implements OutputFormat {
adjust = scfilters.distributeScoreToOutlink((UTF8)key, targetUrl,
parseData, target, null, links.length, validCount);
} catch (ScoringFilterException e) {
- LOG.warn("Cannot distribute score from " + key + " to " + targetUrl +
- " - skipped (" + e.getMessage());
+ if (LOG.isWarnEnabled()) {
+ LOG.warn("Cannot distribute score from " + key + " to " +
+ targetUrl + " - skipped (" + e.getMessage());
+ }
continue;
}
crawlOut.append(targetUrl, target);
diff --git a/src/java/org/apache/nutch/parse/ParsePluginsReader.java b/src/java/org/apache/nutch/parse/ParsePluginsReader.java
index 00a026922..d3548b2ea 100644
--- a/src/java/org/apache/nutch/parse/ParsePluginsReader.java
+++ b/src/java/org/apache/nutch/parse/ParsePluginsReader.java
@@ -93,8 +93,10 @@ class ParsePluginsReader {
parsePluginUrl = new URL(fParsePluginsFile);
ppInputStream = parsePluginUrl.openStream();
} catch (Exception e) {
- LOG.warn("Unable to load parse plugins file from URL " +
- "[" + fParsePluginsFile + "]. Reason is [" + e + "]");
+ if (LOG.isWarnEnabled()) {
+ LOG.warn("Unable to load parse plugins file from URL " +
+ "[" + fParsePluginsFile + "]. Reason is [" + e + "]");
+ }
return pList;
}
} else {
@@ -109,8 +111,10 @@ class ParsePluginsReader {
parser = factory.newDocumentBuilder();
document = parser.parse(inputSource);
} catch (Exception e) {
- LOG.warn("Unable to parse [" + fParsePluginsFile + "]." +
- "Reason is [" + e + "]");
+ if (LOG.isWarnEnabled()) {
+ LOG.warn("Unable to parse [" + fParsePluginsFile + "]." +
+ "Reason is [" + e + "]");
+ }
return null;
}
@@ -163,7 +167,7 @@ class ParsePluginsReader {
// now add the plugin list and map it to this mimeType
pList.setPluginList(mimeTypeStr, plugList);
- } else {
+ } else if (LOG.isWarnEnabled()) {
LOG.warn("ParsePluginsReader:ERROR:no plugins defined for mime type: "
+ mimeTypeStr + ", continuing parse");
}
@@ -240,13 +244,17 @@ class ParsePluginsReader {
NodeList aliasRoot = parsePluginsRoot.getElementsByTagName("aliases");
if (aliasRoot == null || (aliasRoot != null && aliasRoot.getLength() == 0)) {
- LOG.warn("No aliases defined in parse-plugins.xml!");
+ if (LOG.isWarnEnabled()) {
+ LOG.warn("No aliases defined in parse-plugins.xml!");
+ }
return aliases;
}
if (aliasRoot.getLength() > 1) {
// log a warning, but try and continue processing
- LOG.warn("There should only be one \"aliases\" tag in parse-plugins.xml");
+ if (LOG.isWarnEnabled()) {
+ LOG.warn("There should only be one \"aliases\" tag in parse-plugins.xml");
+ }
}
Element aliasRootElem = (Element)aliasRoot.item(0);
@@ -257,8 +265,10 @@ class ParsePluginsReader {
Element aliasElem = (Element)aliasElements.item(i);
String parsePluginId = aliasElem.getAttribute("name");
String extensionId = aliasElem.getAttribute("extension-id");
- LOG.trace("Found alias: plugin-id: " + parsePluginId +
- ", extension-id: " + extensionId);
+ if (LOG.isTraceEnabled()) {
+ LOG.trace("Found alias: plugin-id: " + parsePluginId +
+ ", extension-id: " + extensionId);
+ }
if (parsePluginId != null && extensionId != null) {
aliases.put(parsePluginId, extensionId);
}
diff --git a/src/java/org/apache/nutch/parse/ParseSegment.java b/src/java/org/apache/nutch/parse/ParseSegment.java
index a4d2ffe22..9f798a781 100644
--- a/src/java/org/apache/nutch/parse/ParseSegment.java
+++ b/src/java/org/apache/nutch/parse/ParseSegment.java
@@ -77,12 +77,14 @@ public class ParseSegment extends Configured implements Mapper, Reducer {
try {
scfilters.passScoreAfterParsing((UTF8)key, content, parse);
} catch (ScoringFilterException e) {
- e.printStackTrace(LogUtil.getWarnStream(LOG));
- LOG.warn("Error passing score: "+key+": "+e.getMessage());
+ if (LOG.isWarnEnabled()) {
+ e.printStackTrace(LogUtil.getWarnStream(LOG));
+ LOG.warn("Error passing score: "+key+": "+e.getMessage());
+ }
return;
}
output.collect(key, new ParseImpl(parse.getText(), parse.getData()));
- } else {
+ } else if (LOG.isWarnEnabled()) {
LOG.warn("Error parsing: "+key+": "+status.toString());
}
}
@@ -94,8 +96,11 @@ public class ParseSegment extends Configured implements Mapper, Reducer {
}
public void parse(Path segment) throws IOException {
- LOG.info("Parse: starting");
- LOG.info("Parse: segment: " + segment);
+
+ if (LOG.isInfoEnabled()) {
+ LOG.info("Parse: starting");
+ LOG.info("Parse: segment: " + segment);
+ }
JobConf job = new NutchJob(getConf());
job.setJobName("parse " + segment);
@@ -113,7 +118,7 @@ public class ParseSegment extends Configured implements Mapper, Reducer {
job.setOutputValueClass(ParseImpl.class);
JobClient.runJob(job);
- LOG.info("Parse: done");
+ if (LOG.isInfoEnabled()) { LOG.info("Parse: done"); }
}
diff --git a/src/java/org/apache/nutch/parse/ParseUtil.java b/src/java/org/apache/nutch/parse/ParseUtil.java
index b1132bd6e..fa088a212 100644
--- a/src/java/org/apache/nutch/parse/ParseUtil.java
+++ b/src/java/org/apache/nutch/parse/ParseUtil.java
@@ -67,22 +67,28 @@ public class ParseUtil {
try {
parsers = this.parserFactory.getParsers(content.getContentType(), "");
} catch (ParserNotFound e) {
- LOG.warn("No suitable parser found when trying to parse content " +
- content);
+ if (LOG.isWarnEnabled()) {
+ LOG.warn("No suitable parser found when trying to parse content " +
+ content);
+ }
throw new ParseException(e.getMessage());
}
Parse parse = null;
for (int i=0; i<parsers.length; i++) {
- LOG.debug("Parsing [" + content.getUrl() + "] with [" + parsers[i] + "]");
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Parsing [" + content.getUrl() + "] with [" + parsers[i] + "]");
+ }
parse = parsers[i].getParse(content);
if ((parse != null) && (parse.getData().getStatus().isSuccess())) {
return parse;
}
}
-
- LOG.warn("Unable to successfully parse content " + content.getUrl() +
- " of type " + content.getContentType());
+
+ if (LOG.isWarnEnabled()) {
+ LOG.warn("Unable to successfully parse content " + content.getUrl() +
+ " of type " + content.getContentType());
+ }
ParseStatus ps = (parse.getData() != null) ? parse.getData().getStatus() : null;
return (ps == null) ? new ParseStatus().getEmptyParse(this.conf)
@@ -116,8 +122,10 @@ public class ParseUtil {
try {
p = this.parserFactory.getParserById(extId);
} catch (ParserNotFound e) {
- LOG.warn("No suitable parser found when trying to parse content " +
- content);
+ if (LOG.isWarnEnabled()) {
+ LOG.warn("No suitable parser found when trying to parse content " +
+ content);
+ }
throw new ParseException(e.getMessage());
}
@@ -126,8 +134,10 @@ public class ParseUtil {
if (parse != null && parse.getData().getStatus().isSuccess()) {
return parse;
} else {
- LOG.warn("Unable to successfully parse content " + content.getUrl() +
- " of type " + content.getContentType());
+ if (LOG.isWarnEnabled()) {
+ LOG.warn("Unable to successfully parse content " + content.getUrl() +
+ " of type " + content.getContentType());
+ }
return new ParseStatus().getEmptyParse(this.conf);
}
}
diff --git a/src/java/org/apache/nutch/parse/ParserChecker.java b/src/java/org/apache/nutch/parse/ParserChecker.java
index ead03dbc6..e8f5b9485 100644
--- a/src/java/org/apache/nutch/parse/ParserChecker.java
+++ b/src/java/org/apache/nutch/parse/ParserChecker.java
@@ -70,7 +70,7 @@ public class ParserChecker {
}
}
- LOG.info("fetching: "+url);
+ if (LOG.isInfoEnabled()) { LOG.info("fetching: "+url); }
Configuration conf = NutchConfiguration.create();
ProtocolFactory factory = new ProtocolFactory(conf);
@@ -88,8 +88,10 @@ public class ParserChecker {
System.exit(-1);
}
- LOG.info("parsing: "+url);
- LOG.info("contentType: "+contentType);
+ if (LOG.isInfoEnabled()) {
+ LOG.info("parsing: "+url);
+ LOG.info("contentType: "+contentType);
+ }
Parse parse = new ParseUtil(conf).parse(content);
diff --git a/src/java/org/apache/nutch/parse/ParserFactory.java b/src/java/org/apache/nutch/parse/ParserFactory.java
index 7eba80cc4..94a48838d 100644
--- a/src/java/org/apache/nutch/parse/ParserFactory.java
+++ b/src/java/org/apache/nutch/parse/ParserFactory.java
@@ -131,12 +131,14 @@ public final class ParserFactory {
}
parsers.add(p);
} catch (PluginRuntimeException e) {
+ if (LOG.isWarnEnabled()) {
e.printStackTrace(LogUtil.getWarnStream(LOG));
- LOG.warn("ParserFactory:PluginRuntimeException when "
- + "initializing parser plugin "
- + ext.getDescriptor().getPluginId()
- + " instance in getParsers "
- + "function: attempting to continue instantiating parsers");
+ LOG.warn("ParserFactory:PluginRuntimeException when "
+ + "initializing parser plugin "
+ + ext.getDescriptor().getPluginId()
+ + " instance in getParsers "
+ + "function: attempting to continue instantiating parsers");
+ }
}
}
return (Parser[]) parsers.toArray(new Parser[]{});
@@ -189,9 +191,11 @@ public final class ParserFactory {
this.conf.setObject(parserExt.getId(), p);
return p;
} catch (PluginRuntimeException e) {
- LOG.warn("Canno initialize parser " +
- parserExt.getDescriptor().getPluginId() +
- " (cause: " + e.toString());
+ if (LOG.isWarnEnabled()) {
+ LOG.warn("Canno initialize parser " +
+ parserExt.getDescriptor().getPluginId() +
+ " (cause: " + e.toString());
+ }
throw new ParserNotFound("Cannot init parser for id [" + id + "]");
}
}
@@ -211,8 +215,10 @@ public final class ParserFactory {
try {
type = MimeType.clean(contentType);
} catch (MimeTypeException mte) {
- LOG.debug("Could not clean the content-type [" + contentType +
- "], Reason is [" + mte + "]. Using its raw version...");
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Could not clean the content-type [" + contentType +
+ "], Reason is [" + mte + "]. Using its raw version...");
+ }
type = contentType;
}
@@ -299,22 +305,24 @@ public final class ParserFactory {
if (ext == null) {
//try to get it just by its pluginId
ext = getExtension(extensions, parsePluginId);
-
- if (ext != null) {
- // plugin was enabled via plugin.includes
- // its plugin.xml just doesn't claim to support that
- // particular mimeType
- LOG.warn("ParserFactory:Plugin: " + parsePluginId +
- " mapped to contentType " + contentType +
- " via parse-plugins.xml, but " + "its plugin.xml " +
- "file does not claim to support contentType: " +
- contentType);
- } else {
- // plugin wasn't enabled via plugin.includes
- LOG.warn("ParserFactory: Plugin: " + parsePluginId +
- " mapped to contentType " + contentType +
- " via parse-plugins.xml, but not enabled via " +
- "plugin.includes in nutch-default.xml");
+
+ if (LOG.isWarnEnabled()) {
+ if (ext != null) {
+ // plugin was enabled via plugin.includes
+ // its plugin.xml just doesn't claim to support that
+ // particular mimeType
+ LOG.warn("ParserFactory:Plugin: " + parsePluginId +
+ " mapped to contentType " + contentType +
+ " via parse-plugins.xml, but " + "its plugin.xml " +
+ "file does not claim to support contentType: " +
+ contentType);
+ } else {
+ // plugin wasn't enabled via plugin.includes
+ LOG.warn("ParserFactory: Plugin: " + parsePluginId +
+ " mapped to contentType " + contentType +
+ " via parse-plugins.xml, but not enabled via " +
+ "plugin.includes in nutch-default.xml");
+ }
}
}
@@ -342,12 +350,14 @@ public final class ParserFactory {
}
if (extList.size() > 0) {
- LOG.info("The parsing plugins: " + extList +
- " are enabled via the plugin.includes system " +
- "property, and all claim to support the content type " +
- contentType + ", but they are not mapped to it in the " +
- "parse-plugins.xml file");
- } else {
+ if (LOG.isInfoEnabled()) {
+ LOG.info("The parsing plugins: " + extList +
+ " are enabled via the plugin.includes system " +
+ "property, and all claim to support the content type " +
+ contentType + ", but they are not mapped to it in the " +
+ "parse-plugins.xml file");
+ }
+ } else if (LOG.isDebugEnabled()) {
LOG.debug("ParserFactory:No parse plugins mapped or enabled for " +
"contentType " + contentType);
}
diff --git a/src/java/org/apache/nutch/plugin/PluginDescriptor.java b/src/java/org/apache/nutch/plugin/PluginDescriptor.java
index 8df6d1017..4b66fc258 100644
--- a/src/java/org/apache/nutch/plugin/PluginDescriptor.java
+++ b/src/java/org/apache/nutch/plugin/PluginDescriptor.java
@@ -273,7 +273,9 @@ public class PluginDescriptor {
arrayList.add(file2.getParentFile().toURL());
}
} catch (MalformedURLException e) {
- LOG.debug(getPluginId() + " " + e.toString());
+ if (LOG.isDebugEnabled()) {
+ LOG.debug(getPluginId() + " " + e.toString());
+ }
}
URL[] urls = (URL[]) arrayList.toArray(new URL[arrayList.size()]);
fClassLoader = new PluginClassLoader(urls, PluginDescriptor.class
diff --git a/src/java/org/apache/nutch/plugin/PluginManifestParser.java b/src/java/org/apache/nutch/plugin/PluginManifestParser.java
index cc0b5b0ba..57e9fb8dd 100644
--- a/src/java/org/apache/nutch/plugin/PluginManifestParser.java
+++ b/src/java/org/apache/nutch/plugin/PluginManifestParser.java
@@ -76,9 +76,10 @@ public class PluginManifestParser {
for (int i = 0; i < pluginFolders.length; i++) {
String name = pluginFolders[i];
File directory = getPluginFolder(name);
- if (directory == null)
- continue;
- LOG.info("Plugins: looking in: " + directory.getAbsolutePath());
+ if (directory == null) { continue; }
+ if (LOG.isInfoEnabled()) {
+ LOG.info("Plugins: looking in: " + directory.getAbsolutePath());
+ }
File[] files = directory.listFiles();
if (files == null)
continue;
@@ -88,17 +89,19 @@ public class PluginManifestParser {
String manifestPath = oneSubFolder.getAbsolutePath()
+ File.separator + "plugin.xml";
try {
- LOG.debug("parsing: " + manifestPath);
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("parsing: " + manifestPath);
+ }
PluginDescriptor p = parseManifestFile(manifestPath);
map.put(p.getPluginId(), p);
} catch (MalformedURLException e) {
- LOG.warn(e.toString());
+ if (LOG.isWarnEnabled()) { LOG.warn(e.toString()); }
} catch (SAXException e) {
- LOG.warn(e.toString());
+ if (LOG.isWarnEnabled()) { LOG.warn(e.toString()); }
} catch (IOException e) {
- LOG.warn(e.toString());
+ if (LOG.isWarnEnabled()) { LOG.warn(e.toString()); }
} catch (ParserConfigurationException e) {
- LOG.warn(e.toString());
+ if (LOG.isWarnEnabled()) { LOG.warn(e.toString()); }
}
}
}
@@ -119,11 +122,15 @@ public class PluginManifestParser {
&& directory.isDirectory() && directory.listFiles().length > 0) {
return directory; // relative path that is not in the classpath
} else if (url == null) {
- LOG.warn("Plugins: directory not found: " + name);
+ if (LOG.isWarnEnabled()) {
+ LOG.warn("Plugins: directory not found: " + name);
+ }
return null;
} else if (!"file".equals(url.getProtocol())) {
- LOG.warn("Plugins: not a file: url. Can't load plugins from: "
- + url);
+ if (LOG.isWarnEnabled()) {
+ LOG.warn("Plugins: not a file: url. Can't load plugins from: "
+ + url);
+ }
return null;
}
String path = url.getPath();
@@ -185,8 +192,10 @@ public class PluginManifestParser {
}
PluginDescriptor pluginDescriptor = new PluginDescriptor(id, version,
name, providerName, pluginClazz, pPath, this.conf);
- LOG.debug("plugin: id="+id+" name="+name+" version="+version
- +" provider="+providerName+"class="+pluginClazz);
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("plugin: id="+id+" name="+name+" version="+version
+ +" provider="+providerName+"class="+pluginClazz);
+ }
parseExtension(rootElement, pluginDescriptor);
parseExtensionPoints(rootElement, pluginDescriptor);
parseLibraries(rootElement, pluginDescriptor);
@@ -260,7 +269,7 @@ public class PluginManifestParser {
String schema = oneExtensionPoint.getAttribute("schema");
ExtensionPoint extensionPoint = new ExtensionPoint(id, name,
schema);
- //LOG.debug("plugin: point="+id);
+ //if (LOG.isDebugEnabled()) { LOG.debug("plugin: point="+id); }
pPluginDescriptor.addExtensionPoint(extensionPoint);
}
}
@@ -290,8 +299,10 @@ public class PluginManifestParser {
String id = oneImplementation.getAttribute("id");
String extensionClass = oneImplementation
.getAttribute("class");
- LOG.debug("impl: point=" + pointId + " class="
- + extensionClass);
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("impl: point=" + pointId + " class="
+ + extensionClass);
+ }
Extension extension = new Extension(pPluginDescriptor,
pointId, id, extensionClass, this.conf, this.pluginRepository);
NodeList parameters = oneImplementation.getElementsByTagName("parameter");
diff --git a/src/java/org/apache/nutch/plugin/PluginRepository.java b/src/java/org/apache/nutch/plugin/PluginRepository.java
index bdaa5c4b0..a778d9bf4 100644
--- a/src/java/org/apache/nutch/plugin/PluginRepository.java
+++ b/src/java/org/apache/nutch/plugin/PluginRepository.java
@@ -91,7 +91,7 @@ public class PluginRepository {
try {
installExtensions(fRegisteredPlugins);
} catch (PluginRuntimeException e) {
- LOG.fatal(e.toString());
+ if (LOG.isFatalEnabled()) { LOG.fatal(e.toString()); }
throw new RuntimeException(e.getMessage());
}
displayStatus();
@@ -119,7 +119,9 @@ public class PluginRepository {
for (int j=0; j<points.length; j++) {
ExtensionPoint point = points[j];
String xpId = point.getId();
- LOG.debug("Adding extension point " + xpId);
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Adding extension point " + xpId);
+ }
fExtensionPoints.put(xpId, point);
}
}
@@ -210,10 +212,10 @@ public class PluginRepository {
checked.put(plugin.getPluginId(), plugin);
} catch (MissingDependencyException mde) {
// Simply ignore this plugin
- LOG.warn(mde.getMessage());
+ if (LOG.isWarnEnabled()) { LOG.warn(mde.getMessage()); }
} catch (CircularDependencyException cde) {
// Simply ignore this plugin
- LOG.warn(cde.getMessage());
+ if (LOG.isWarnEnabled()) { LOG.warn(cde.getMessage()); }
}
}
return new ArrayList(checked.values());
@@ -326,9 +328,11 @@ public class PluginRepository {
private void displayStatus() {
+ if (!LOG.isInfoEnabled()) { return; }
+
LOG.info("Plugin Auto-activation mode: [" + this.auto + "]");
-
LOG.info("Registered Plugins:");
+
if ((fRegisteredPlugins == null) || (fRegisteredPlugins.size() == 0)) {
LOG.info("\tNONE");
} else {
@@ -366,11 +370,11 @@ public class PluginRepository {
if (id == null) { continue; }
if (!includes.matcher(id).matches()) {
- LOG.debug("not including: " + id);
+ if (LOG.isDebugEnabled()) { LOG.debug("not including: " + id); }
continue;
}
if (excludes.matcher(id).matches()) {
- LOG.debug("excluding: " + id);
+ if (LOG.isDebugEnabled()) { LOG.debug("excluding: " + id); }
continue;
}
map.put(plugin.getPluginId(), plugin);
diff --git a/src/java/org/apache/nutch/searcher/DistributedSearch.java b/src/java/org/apache/nutch/searcher/DistributedSearch.java
index 663e434d8..d1e82ef3d 100644
--- a/src/java/org/apache/nutch/searcher/DistributedSearch.java
+++ b/src/java/org/apache/nutch/searcher/DistributedSearch.java
@@ -111,7 +111,9 @@ public class DistributedSearch {
if (tokens.hasMoreTokens()) {
String port = tokens.nextToken();
addrs.add(new InetSocketAddress(host, Integer.parseInt(port)));
- LOG.info("Client adding server " + host + ":" + port);
+ if (LOG.isInfoEnabled()) {
+ LOG.info("Client adding server " + host + ":" + port);
+ }
}
}
}
@@ -171,11 +173,15 @@ public class DistributedSearch {
InetSocketAddress addr = defaultAddresses[i];
String[] segments = results[i];
if (segments == null) {
- LOG.warn("Client: no segments from: " + addr);
+ if (LOG.isWarnEnabled()) {
+ LOG.warn("Client: no segments from: " + addr);
+ }
continue;
}
for (int j = 0; j < segments.length; j++) {
- LOG.trace("Client: segment "+segments[j]+" at "+addr);
+ if (LOG.isTraceEnabled()) {
+ LOG.trace("Client: segment "+segments[j]+" at "+addr);
+ }
segmentToAddress.put(segments[j], addr);
}
liveAddresses.add(addr);
@@ -184,9 +190,11 @@ public class DistributedSearch {
}
this.liveAddresses = (InetSocketAddress[]) // update liveAddresses
- liveAddresses.toArray(new InetSocketAddress[liveAddresses.size()]);
+ liveAddresses.toArray(new InetSocketAddress[liveAddresses.size()]);
- LOG.info("STATS: "+liveServers+" servers, "+liveSegments+" segments.");
+ if (LOG.isInfoEnabled()) {
+ LOG.info("STATS: "+liveServers+" servers, "+liveSegments+" segments.");
+ }
}
/** Return the names of segments searched. */
@@ -349,13 +357,17 @@ public class DistributedSearch {
try{
Thread.sleep(10000);
} catch (InterruptedException ie){
- LOG.info("Thread sleep interrupted.");
+ if (LOG.isInfoEnabled()) {
+ LOG.info("Thread sleep interrupted.");
+ }
}
try{
- LOG.info("Querying segments from search servers...");
+ if (LOG.isInfoEnabled()) {
+ LOG.info("Querying segments from search servers...");
+ }
updateSegments();
} catch (IOException ioe) {
- LOG.warn("No search servers available!");
+ if (LOG.isWarnEnabled()) { LOG.warn("No search servers available!"); }
liveAddresses=new InetSocketAddress[0];
}
}
diff --git a/src/java/org/apache/nutch/searcher/NutchBean.java b/src/java/org/apache/nutch/searcher/NutchBean.java
index 9e7134503..38d48f20d 100644
--- a/src/java/org/apache/nutch/searcher/NutchBean.java
+++ b/src/java/org/apache/nutch/searcher/NutchBean.java
@@ -66,7 +66,7 @@ public class NutchBean
public static NutchBean get(ServletContext app, Configuration conf) throws IOException {
NutchBean bean = (NutchBean)app.getAttribute("nutchBean");
if (bean == null) {
- LOG.info("creating new bean");
+ if (LOG.isInfoEnabled()) { LOG.info("creating new bean"); }
bean = new NutchBean(conf);
app.setAttribute("nutchBean", bean);
}
@@ -97,7 +97,9 @@ public class NutchBean
}
Path servers = new Path(dir, "search-servers.txt");
if (fs.exists(servers)) {
- LOG.info("searching servers in " + servers);
+ if (LOG.isInfoEnabled()) {
+ LOG.info("searching servers in " + servers);
+ }
init(new DistributedSearch.Client(servers, conf));
} else {
init(new Path(dir, "index"), new Path(dir, "indexes"), new Path(
@@ -110,10 +112,14 @@ public class NutchBean
throws IOException {
IndexSearcher indexSearcher;
if (this.fs.exists(indexDir)) {
- LOG.info("opening merged index in " + indexDir);
+ if (LOG.isInfoEnabled()) {
+ LOG.info("opening merged index in " + indexDir);
+ }
indexSearcher = new IndexSearcher(indexDir, this.conf);
} else {
- LOG.info("opening indexes in " + indexesDir);
+ if (LOG.isInfoEnabled()) {
+ LOG.info("opening indexes in " + indexesDir);
+ }
Vector vDirs=new Vector();
Path [] directories = fs.listPaths(indexesDir);
@@ -133,7 +139,9 @@ public class NutchBean
indexSearcher = new IndexSearcher(directories, this.conf);
}
- LOG.info("opening segments in " + segmentsDir);
+ if (LOG.isInfoEnabled()) {
+ LOG.info("opening segments in " + segmentsDir);
+ }
FetchedSegments segments = new FetchedSegments(this.fs, segmentsDir.toString(),this.conf);
this.segmentNames = segments.getSegmentNames();
@@ -143,7 +151,7 @@ public class NutchBean
this.summarizer = segments;
this.content = segments;
- LOG.info("opening linkdb in " + linkDb);
+ if (LOG.isInfoEnabled()) { LOG.info("opening linkdb in " + linkDb); }
this.linkDb = new LinkDbInlinks(fs, linkDb, this.conf);
}
@@ -235,7 +243,9 @@ public class NutchBean
float rawHitsFactor = this.conf.getFloat("searcher.hostgrouping.rawhits.factor", 2.0f);
int numHitsRaw = (int)(numHits * rawHitsFactor);
- LOG.info("searching for "+numHitsRaw+" raw hits");
+ if (LOG.isInfoEnabled()) {
+ LOG.info("searching for "+numHitsRaw+" raw hits");
+ }
Hits hits = searcher.search(query, numHitsRaw,
dedupField, sortField, reverse);
long total = hits.getTotal();
@@ -256,10 +266,14 @@ public class NutchBean
dedupField);
}
numHitsRaw = (int)(numHitsRaw * rawHitsFactor);
- LOG.info("re-searching for "+numHitsRaw+" raw hits, query: "+optQuery);
+ if (LOG.isInfoEnabled()) {
+ LOG.info("re-searching for "+numHitsRaw+" raw hits, query: "+optQuery);
+ }
hits = searcher.search(optQuery, numHitsRaw,
dedupField, sortField, reverse);
- LOG.info("found "+hits.getTotal()+" raw hits");
+ if (LOG.isInfoEnabled()) {
+ LOG.info("found "+hits.getTotal()+" raw hits");
+ }
rawHitNum = -1;
continue;
}
diff --git a/src/java/org/apache/nutch/searcher/OpenSearchServlet.java b/src/java/org/apache/nutch/searcher/OpenSearchServlet.java
index 6b02e5ab6..a5b1386f2 100644
--- a/src/java/org/apache/nutch/searcher/OpenSearchServlet.java
+++ b/src/java/org/apache/nutch/searcher/OpenSearchServlet.java
@@ -71,7 +71,9 @@ public class OpenSearchServlet extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
- NutchBean.LOG.info("query request from " + request.getRemoteAddr());
+ if (NutchBean.LOG.isInfoEnabled()) {
+ NutchBean.LOG.info("query request from " + request.getRemoteAddr());
+ }
// get parameters from request
request.setCharacterEncoding("UTF-8");
@@ -123,8 +125,10 @@ public class OpenSearchServlet extends HttpServlet {
(dedupField == null ? "" : "&dedupField=" + dedupField));
Query query = Query.parse(queryString, queryLang, this.conf);
- NutchBean.LOG.info("query: " + queryString);
- NutchBean.LOG.info("lang: " + queryLang);
+ if (NutchBean.LOG.isInfoEnabled()) {
+ NutchBean.LOG.info("query: " + queryString);
+ NutchBean.LOG.info("lang: " + queryLang);
+ }
// execute the query
Hits hits;
@@ -132,11 +136,15 @@ public class OpenSearchServlet extends HttpServlet {
hits = bean.search(query, start + hitsPerPage, hitsPerDup, dedupField,
sort, reverse);
} catch (IOException e) {
- NutchBean.LOG.warn("Search Error", e);
+ if (NutchBean.LOG.isWarnEnabled()) {
+ NutchBean.LOG.warn("Search Error", e);
+ }
hits = new Hits(0,new Hit[0]);
}
- NutchBean.LOG.info("total hits: " + hits.getTotal());
+ if (NutchBean.LOG.isInfoEnabled()) {
+ NutchBean.LOG.info("total hits: " + hits.getTotal());
+ }
// generate xml results
int end = (int)Math.min(hits.getLength(), start + hitsPerPage);
diff --git a/src/java/org/apache/nutch/searcher/QueryFilters.java b/src/java/org/apache/nutch/searcher/QueryFilters.java
index 863ebcdee..a1f920b37 100644
--- a/src/java/org/apache/nutch/searcher/QueryFilters.java
+++ b/src/java/org/apache/nutch/searcher/QueryFilters.java
@@ -66,8 +66,10 @@ public class QueryFilters {
ArrayList fieldNames = parseFieldNames(extension, "fields");
ArrayList rawFieldNames = parseFieldNames(extension, "raw-fields");
if (fieldNames.size() == 0 && rawFieldNames.size() == 0) {
- LOG.warn("QueryFilter: " + extension.getId()
- + " names no fields.");
+ if (LOG.isWarnEnabled()) {
+ LOG.warn("QueryFilter: " + extension.getId()
+ + " names no fields.");
+ }
continue;
}
filters[i] = (QueryFilter) extension.getExtensionInstance();
diff --git a/src/java/org/apache/nutch/searcher/SummarizerFactory.java b/src/java/org/apache/nutch/searcher/SummarizerFactory.java
index 8e9725cfa..92416c1ce 100644
--- a/src/java/org/apache/nutch/searcher/SummarizerFactory.java
+++ b/src/java/org/apache/nutch/searcher/SummarizerFactory.java
@@ -48,10 +48,12 @@ public class SummarizerFactory {
.getExtensionPoint(Summarizer.X_POINT_ID)
.getExtensions();
summarizer = (Summarizer) extensions[0].getExtensionInstance();
- LOG.info("Using the first summarizer extension found: " +
- extensions[0].getId());
+ if (LOG.isInfoEnabled()) {
+ LOG.info("Using the first summarizer extension found: " +
+ extensions[0].getId());
+ }
} catch (Exception e) {
- LOG.warn(e.toString());
+ if (LOG.isWarnEnabled()) { LOG.warn(e.toString()); }
}
}
diff --git a/src/java/org/apache/nutch/segment/SegmentMerger.java b/src/java/org/apache/nutch/segment/SegmentMerger.java
index 4cc97b9da..fad4b4431 100644
--- a/src/java/org/apache/nutch/segment/SegmentMerger.java
+++ b/src/java/org/apache/nutch/segment/SegmentMerger.java
@@ -316,8 +316,9 @@ public class SegmentMerger extends Configured implements Mapper, Reducer {
if (conf.getBoolean("segment.merger.filter", false))
filters = new URLFilters(conf);
sliceSize = conf.getLong("segment.merger.slice", -1);
- if (sliceSize > 0)
+ if ((sliceSize > 0) && (LOG.isInfoEnabled())) {
LOG.info("Slice size: " + sliceSize + " URLs.");
+ }
}
public void close() throws IOException {
@@ -337,7 +338,9 @@ public class SegmentMerger extends Configured implements Mapper, Reducer {
return;
}
} catch (Exception e) {
- LOG.warn("Cannot filter key " + key + ": " + e.getMessage());
+ if (LOG.isWarnEnabled()) {
+ LOG.warn("Cannot filter key " + key + ": " + e.getMessage());
+ }
}
}
output.collect(key, value);
@@ -531,9 +534,11 @@ public class SegmentMerger extends Configured implements Mapper, Reducer {
public void merge(Path out, Path[] segs, boolean filter, long slice) throws Exception {
String segmentName = Generator.generateSegmentName();
+ if (LOG.isInfoEnabled()) {
+ LOG.info("Merging " + segs.length + " segments to " + out + "/" + segmentName);
+ }
JobConf job = new JobConf(getConf());
job.setJobName("mergesegs " + out + "/" + segmentName);
- LOG.info("Merging " + segs.length + " segments to " + out + "/" + segmentName);
job.setBoolean("segment.merger.filter", filter);
job.setLong("segment.merger.slice", slice);
job.set("segment.merger.segmentName", segmentName);
@@ -547,11 +552,15 @@ public class SegmentMerger extends Configured implements Mapper, Reducer {
boolean pt = true;
for (int i = 0; i < segs.length; i++) {
if (!fs.exists(segs[i])) {
- LOG.warn("SegmentMerger: input dir " + segs[i] + " doesn't exist, skipping.");
+ if (LOG.isWarnEnabled()) {
+ LOG.warn("Input dir " + segs[i] + " doesn't exist, skipping.");
+ }
segs[i] = null;
continue;
}
- LOG.info("SegmentMerger: adding " + segs[i]);
+ if (LOG.isInfoEnabled()) {
+ LOG.info("SegmentMerger: adding " + segs[i]);
+ }
Path cDir = new Path(segs[i], Content.DIR_NAME);
Path gDir = new Path(segs[i], CrawlDatum.GENERATE_DIR_NAME);
Path fDir = new Path(segs[i], CrawlDatum.FETCH_DIR_NAME);
@@ -572,7 +581,9 @@ public class SegmentMerger extends Configured implements Mapper, Reducer {
if (p) sb.append(" " + CrawlDatum.PARSE_DIR_NAME);
if (pd) sb.append(" " + ParseData.DIR_NAME);
if (pt) sb.append(" " + ParseText.DIR_NAME);
- LOG.info("SegmentMerger: using segment data from:" + sb.toString());
+ if (LOG.isInfoEnabled()) {
+ LOG.info("SegmentMerger: using segment data from:" + sb.toString());
+ }
for (int i = 0; i < segs.length; i++) {
if (segs[i] == null) continue;
if (g) {
diff --git a/src/java/org/apache/nutch/segment/SegmentReader.java b/src/java/org/apache/nutch/segment/SegmentReader.java
index ae85741b4..d84838a4e 100644
--- a/src/java/org/apache/nutch/segment/SegmentReader.java
+++ b/src/java/org/apache/nutch/segment/SegmentReader.java
@@ -155,7 +155,7 @@ public class SegmentReader extends Configured implements Reducer {
dump.append("\nParseData::\n").append(((ParseData) value).toString());
} else if (value instanceof ParseText) {
dump.append("\nParseText::\n").append(((ParseText) value).toString());
- } else {
+ } else if (LOG.isWarnEnabled()) {
LOG.warn("Unrecognized type: " + value.getClass());
}
}
@@ -163,7 +163,10 @@ public class SegmentReader extends Configured implements Reducer {
}
public void dump(Path segment, Path output) throws IOException {
- LOG.info("SegmentReader: dump segment: " + segment);
+
+ if (LOG.isInfoEnabled()) {
+ LOG.info("SegmentReader: dump segment: " + segment);
+ }
JobConf job = createJobConf();
job.setJobName("read " + segment);
@@ -208,8 +211,11 @@ public class SegmentReader extends Configured implements Reducer {
try {
currentRecordNumber = append(fs, job, partFile, writer, currentRecordNumber);
} catch (IOException exception) {
- LOG.warn("Couldn't copy the content of " + partFile.toString() + " into " + dumpFile.toString());
- LOG.warn(exception.getMessage());
+ if (LOG.isWarnEnabled()) {
+ LOG.warn("Couldn't copy the content of " + partFile.toString() +
+ " into " + dumpFile.toString());
+ LOG.warn(exception.getMessage());
+ }
}
}
} finally {
@@ -217,7 +223,7 @@ public class SegmentReader extends Configured implements Reducer {
}
}
fs.delete(tempDir);
- LOG.info("SegmentReader: done");
+ if (LOG.isInfoEnabled()) { LOG.info("SegmentReader: done"); }
}
/** Appends two files and updates the Recno counter */
@@ -250,7 +256,7 @@ public class SegmentReader extends Configured implements Reducer {
public void get(final Path segment, final UTF8 key, Writer writer,
final Map results) throws Exception {
- LOG.info("SegmentReader: get '" + key + "'");
+ if (LOG.isInfoEnabled()) { LOG.info("SegmentReader: get '" + key + "'"); }
ArrayList threads = new ArrayList();
if (co) threads.add(new Thread() {
public void run() {
@@ -323,7 +329,9 @@ public class SegmentReader extends Configured implements Reducer {
while (it.hasNext()) {
if (((Thread)it.next()).isAlive()) cnt++;
}
- if (cnt > 0) LOG.debug("(" + cnt + " to retrieve)");
+ if ((cnt > 0) && (LOG.isDebugEnabled())) {
+ LOG.debug("(" + cnt + " to retrieve)");
+ }
} while (cnt > 0);
for (int i = 0; i < keys.length; i++) {
List res = (List)results.get(keys[i][0]);
diff --git a/src/java/org/apache/nutch/servlet/Cached.java b/src/java/org/apache/nutch/servlet/Cached.java
index 7b09b0402..680ddccf3 100644
--- a/src/java/org/apache/nutch/servlet/Cached.java
+++ b/src/java/org/apache/nutch/servlet/Cached.java
@@ -70,7 +70,9 @@ public class Cached extends HttpServlet {
if (bean == null)
return;
- bean.LOG.info("request from " + request.getRemoteAddr());
+ if (bean.LOG.isInfoEnabled()) {
+ bean.LOG.info("request from " + request.getRemoteAddr());
+ }
Hit hit = new Hit(Integer.parseInt(request.getParameter("idx")),
Integer.parseInt(request.getParameter("id")));
diff --git a/src/java/org/apache/nutch/tools/DmozParser.java b/src/java/org/apache/nutch/tools/DmozParser.java
index 52196fab6..2af17e266 100644
--- a/src/java/org/apache/nutch/tools/DmozParser.java
+++ b/src/java/org/apache/nutch/tools/DmozParser.java
@@ -180,7 +180,7 @@ public class DmozParser {
// Inc the number of pages, insert the page, and
// possibly print status.
//
- LOG.info(curURL);
+ if (LOG.isInfoEnabled()) { LOG.info(curURL); }
pages++;
//
@@ -208,14 +208,16 @@ public class DmozParser {
* When parsing begins
*/
public void startDocument() {
- LOG.info("Begin parse");
+ if (LOG.isInfoEnabled()) { LOG.info("Begin parse"); }
}
/**
* When parsing ends
*/
public void endDocument() {
- LOG.info("Completed parse. Found " + pages + " pages.");
+ if (LOG.isInfoEnabled()) {
+ LOG.info("Completed parse. Found " + pages + " pages.");
+ }
}
/**
@@ -236,25 +238,32 @@ public class DmozParser {
* Emit the exception message
*/
public void error(SAXParseException spe) {
- LOG.fatal("Error: " + spe.toString() + ": " + spe.getMessage());
- spe.printStackTrace(LogUtil.getFatalStream(LOG));
+ if (LOG.isFatalEnabled()) {
+ LOG.fatal("Error: " + spe.toString() + ": " + spe.getMessage());
+ spe.printStackTrace(LogUtil.getFatalStream(LOG));
+ }
}
/**
* Emit the exception message, with line numbers
*/
public void fatalError(SAXParseException spe) {
- LOG.fatal("Fatal err: " + spe.toString() + ": " + spe.getMessage());
- LOG.fatal("Last known line is " + location.getLineNumber() + ", column " + location.getColumnNumber());
- spe.printStackTrace(LogUtil.getFatalStream(LOG));
+ if (LOG.isFatalEnabled()) {
+ LOG.fatal("Fatal err: " + spe.toString() + ": " + spe.getMessage());
+ LOG.fatal("Last known line is " + location.getLineNumber() +
+ ", column " + location.getColumnNumber());
+ spe.printStackTrace(LogUtil.getFatalStream(LOG));
+ }
}
/**
* Emit exception warning message
*/
public void warning(SAXParseException spe) {
- LOG.warn("Warning: " + spe.toString() + ": " + spe.getMessage());
- spe.printStackTrace(LogUtil.getFatalStream(LOG));
+ if (LOG.isWarnEnabled()) {
+ LOG.warn("Warning: " + spe.toString() + ": " + spe.getMessage());
+ spe.printStackTrace(LogUtil.getWarnStream(LOG));
+ }
}
}
@@ -279,7 +288,7 @@ public class DmozParser {
skew, topicPattern);
reader.setContentHandler(rp);
reader.setErrorHandler(rp);
- LOG.info("skew = " + rp.hashSkew);
+ if (LOG.isInfoEnabled()) { LOG.info("skew = " + rp.hashSkew); }
//
// Open filtered text stream. The UTF8Filter makes sure that
@@ -291,8 +300,10 @@ public class DmozParser {
InputSource is = new InputSource(in);
reader.parse(is);
} catch (Exception e) {
- LOG.fatal(e.toString());
- e.printStackTrace(LogUtil.getFatalStream(LOG));
+ if (LOG.isFatalEnabled()) {
+ LOG.fatal(e.toString());
+ e.printStackTrace(LogUtil.getFatalStream(LOG));
+ }
System.exit(0);
} finally {
in.close();
@@ -310,8 +321,10 @@ public class DmozParser {
}
}
catch (Exception e) {
- LOG.fatal(e.toString());
- e.printStackTrace(LogUtil.getFatalStream(LOG));
+ if (LOG.isFatalEnabled()) {
+ LOG.fatal(e.toString());
+ e.printStackTrace(LogUtil.getFatalStream(LOG));
+ }
System.exit(0);
} finally {
in.close();
@@ -372,7 +385,9 @@ public class DmozParser {
}
regExp = regExp.concat((String) topics.get(j));
regExp = regExp.concat(").*");
- LOG.info("Topic selection pattern = " + regExp);
+ if (LOG.isInfoEnabled()) {
+ LOG.info("Topic selection pattern = " + regExp);
+ }
topicPattern = Pattern.compile(regExp);
}
diff --git a/src/java/org/apache/nutch/tools/PruneIndexTool.java b/src/java/org/apache/nutch/tools/PruneIndexTool.java
index 795a10650..78055c9e0 100644
--- a/src/java/org/apache/nutch/tools/PruneIndexTool.java
+++ b/src/java/org/apache/nutch/tools/PruneIndexTool.java
@@ -189,7 +189,9 @@ public class PruneIndexTool implements Runnable {
output.flush();
output.close();
} catch (Exception e) {
- LOG.warn("Error closing: " + e.getMessage());
+ if (LOG.isWarnEnabled()) {
+ LOG.warn("Error closing: " + e.getMessage());
+ }
}
}
@@ -257,7 +259,9 @@ public class PruneIndexTool implements Runnable {
}
if (!dryrun) {
IndexReader.unlock(dir);
- LOG.debug(" - had to unlock index in " + dir);
+ if (LOG.isDebugEnabled()) {
+ LOG.debug(" - had to unlock index in " + dir);
+ }
}
}
reader = IndexReader.open(dir);
@@ -270,26 +274,35 @@ public class PruneIndexTool implements Runnable {
dir = FSDirectory.getDirectory(indexDirs[i], false);
if (IndexReader.isLocked(dir)) {
if (!unlock) {
- LOG.warn(dr + "Index " + indexDirs[i] + " is locked. Skipping...");
+ if (LOG.isWarnEnabled()) {
+ LOG.warn(dr + "Index " + indexDirs[i] + " is locked. Skipping...");
+ }
continue;
}
if (!dryrun) {
IndexReader.unlock(dir);
- LOG.debug(" - had to unlock index in " + dir);
+ if (LOG.isDebugEnabled()) {
+ LOG.debug(" - had to unlock index in " + dir);
+ }
}
}
IndexReader r = IndexReader.open(dir);
indexes.add(r);
numIdx++;
} catch (Exception e) {
- LOG.warn(dr + "Invalid index in " + indexDirs[i] + " - skipping...");
+ if (LOG.isWarnEnabled()) {
+ LOG.warn(dr + "Invalid index in " + indexDirs[i] + " - skipping...");
+ }
}
}
if (indexes.size() == 0) throw new Exception("No input indexes.");
IndexReader[] readers = (IndexReader[])indexes.toArray(new IndexReader[0]);
reader = new MultiReader(readers);
}
- LOG.info(dr + "Opened " + numIdx + " index(es) with total " + reader.numDocs() + " documents.");
+ if (LOG.isInfoEnabled()) {
+ LOG.info(dr + "Opened " + numIdx + " index(es) with total " +
+ reader.numDocs() + " documents.");
+ }
searcher = new IndexSearcher(reader);
}
@@ -322,19 +335,27 @@ public class PruneIndexTool implements Runnable {
AllHitsCollector ahc = new AllHitsCollector(bits);
boolean doDelete = false;
for (int i = 0; i < queries.length; i++) {
- LOG.info(dr + "Processing query: " + queries[i].toString());
+ if (LOG.isInfoEnabled()) {
+ LOG.info(dr + "Processing query: " + queries[i].toString());
+ }
bits.clear();
try {
searcher.search(queries[i], ahc);
} catch (IOException e) {
- LOG.warn(dr + " - failed: " + e.getMessage());
+ if (LOG.isWarnEnabled()) {
+ LOG.warn(dr + " - failed: " + e.getMessage());
+ }
continue;
}
if (bits.cardinality() == 0) {
- LOG.info(dr + " - no matching documents.");
+ if (LOG.isInfoEnabled()) {
+ LOG.info(dr + " - no matching documents.");
+ }
continue;
}
- LOG.info(dr + " - found " + bits.cardinality() + " document(s).");
+ if (LOG.isInfoEnabled()) {
+ LOG.info(dr + " - found " + bits.cardinality() + " document(s).");
+ }
// Now delete all matching documents
int docNum = -1, start = 0, cnt = 0;
// probably faster than looping sequentially through all index values?
@@ -355,11 +376,15 @@ public class PruneIndexTool implements Runnable {
cnt++;
}
} catch (Exception e) {
- LOG.warn(dr + " - failed to delete doc #" + docNum);
+ if (LOG.isWarnEnabled()) {
+ LOG.warn(dr + " - failed to delete doc #" + docNum);
+ }
}
start = docNum + 1;
}
- LOG.info(dr + " - deleted " + cnt + " document(s).");
+ if (LOG.isInfoEnabled()) {
+ LOG.info(dr + " - deleted " + cnt + " document(s).");
+ }
}
// close checkers
if (checkers != null) {
@@ -370,20 +395,22 @@ public class PruneIndexTool implements Runnable {
try {
reader.close();
} catch (IOException e) {
- LOG.warn(dr + "Exception when closing reader(s): " + e.getMessage());
+ if (LOG.isWarnEnabled()) {
+ LOG.warn(dr + "Exception when closing reader(s): " + e.getMessage());
+ }
}
}
public static void main(String[] args) throws Exception {
if (args.length == 0) {
usage();
- LOG.fatal("Missing arguments");
+ if (LOG.isFatalEnabled()) { LOG.fatal("Missing arguments"); }
return;
}
File idx = new File(args[0]);
if (!idx.isDirectory()) {
usage();
- LOG.fatal("Not a directory: " + idx);
+ if (LOG.isFatalEnabled()) { LOG.fatal("Not a directory: " + idx); }
return;
}
Vector paths = new Vector();
@@ -398,7 +425,7 @@ public class PruneIndexTool implements Runnable {
});
if (dirs == null || dirs.length == 0) {
usage();
- LOG.fatal("No indexes in " + idx);
+ if (LOG.isFatalEnabled()) { LOG.fatal("No indexes in " + idx); }
return;
}
for (int i = 0; i < dirs.length; i++) {
@@ -409,7 +436,9 @@ public class PruneIndexTool implements Runnable {
}
if (paths.size() == 0) {
usage();
- LOG.fatal("No indexes in " + idx + " or its subdirs.");
+ if (LOG.isFatalEnabled()) {
+ LOG.fatal("No indexes in " + idx + " or its subdirs.");
+ }
return;
}
}
@@ -432,7 +461,9 @@ public class PruneIndexTool implements Runnable {
dryrun = true;
} else {
usage();
- LOG.fatal("Unrecognized option: " + args[i]);
+ if (LOG.isFatalEnabled()) {
+ LOG.fatal("Unrecognized option: " + args[i]);
+ }
return;
}
}
@@ -465,20 +496,26 @@ public class PruneIndexTool implements Runnable {
is = conf.getConfResourceAsInputStream(qPath);
}
if (is == null) {
- LOG.fatal("Can't load queries from " + qPath);
+ if (LOG.isFatalEnabled()) {
+ LOG.fatal("Can't load queries from " + qPath);
+ }
return;
}
try {
queries = parseQueries(is);
} catch (Exception e) {
- LOG.fatal("Error parsing queries: " + e.getMessage());
+ if (LOG.isFatalEnabled()) {
+ LOG.fatal("Error parsing queries: " + e.getMessage());
+ }
return;
}
try {
PruneIndexTool pit = new PruneIndexTool(indexes, queries, checkers, force, dryrun);
pit.run();
} catch (Exception e) {
- LOG.fatal("Error running PruneIndexTool: " + e.getMessage());
+ if (LOG.isFatalEnabled()) {
+ LOG.fatal("Error running PruneIndexTool: " + e.getMessage());
+ }
return;
}
}
diff --git a/src/java/org/apache/nutch/util/LogUtil.java b/src/java/org/apache/nutch/util/LogUtil.java
index 21511b23e..4000425c7 100644
--- a/src/java/org/apache/nutch/util/LogUtil.java
+++ b/src/java/org/apache/nutch/util/LogUtil.java
@@ -51,7 +51,9 @@ public class LogUtil {
ERROR = Log.class.getMethod("error", new Class[] { Object.class });
FATAL = Log.class.getMethod("fatal", new Class[] { Object.class });
} catch(Exception e) {
- LOG.error("Cannot init log methods", e);
+ if (LOG.isErrorEnabled()) {
+ LOG.error("Cannot init log methods", e);
+ }
}
}
@@ -99,7 +101,9 @@ public class LogUtil {
try {
method.invoke(logger, new Object[] { toString().trim() });
} catch (Exception e) {
- LOG.fatal("Cannot log with method [" + method + "]", e);
+ if (LOG.isFatalEnabled()) {
+ LOG.fatal("Cannot log with method [" + method + "]", e);
+ }
}
reset();
scan = 0;
diff --git a/src/java/org/apache/nutch/util/ThreadPool.java b/src/java/org/apache/nutch/util/ThreadPool.java
index f9abf7865..22d876fc9 100644
--- a/src/java/org/apache/nutch/util/ThreadPool.java
+++ b/src/java/org/apache/nutch/util/ThreadPool.java
@@ -74,7 +74,9 @@ public class ThreadPool {
t.start();
}
Log l = LogFactory.getLog("org.apache.nutch.util");
- l.debug("ThreadPool created with " + numThreads + " threads.");
+ if (l.isDebugEnabled()) {
+ l.debug("ThreadPool created with " + numThreads + " threads.");
+ }
}
/**
@@ -130,6 +132,8 @@ public class ThreadPool {
public void shutdown() {
running = false;
Log l = LogFactory.getLog("org.apache.nutch.util");
- l.debug("ThreadPool shutting down.");
+ if (l.isDebugEnabled()) {
+ l.debug("ThreadPool shutting down.");
+ }
}
}
diff --git a/src/java/org/apache/nutch/util/mime/MimeTypesReader.java b/src/java/org/apache/nutch/util/mime/MimeTypesReader.java
index 03e7614f5..cb8f049c4 100644
--- a/src/java/org/apache/nutch/util/mime/MimeTypesReader.java
+++ b/src/java/org/apache/nutch/util/mime/MimeTypesReader.java
@@ -68,7 +68,9 @@ final class MimeTypesReader {
Document document = builder.parse(new InputSource(stream));
types = visit(document);
} catch (Exception e) {
- logger.warn(e.toString() + " while loading mime-types");
+ if (logger.isWarnEnabled()) {
+ logger.warn(e.toString() + " while loading mime-types");
+ }
types = new MimeType[0];
}
return types;
diff --git a/src/plugin/clustering-carrot2/src/java/org/apache/nutch/clustering/carrot2/Clusterer.java b/src/plugin/clustering-carrot2/src/java/org/apache/nutch/clustering/carrot2/Clusterer.java
index df5b375af..e6ce68b70 100644
--- a/src/plugin/clustering-carrot2/src/java/org/apache/nutch/clustering/carrot2/Clusterer.java
+++ b/src/plugin/clustering-carrot2/src/java/org/apache/nutch/clustering/carrot2/Clusterer.java
@@ -128,13 +128,19 @@ public class Clusterer implements OnlineClusterer, Configurable {
try {
Language lang = AllKnownLanguages.getLanguageForIsoCode(lcode);
if (lang == null) {
- logger.warn("Language not supported in Carrot2: " + lcode);
+ if (logger.isWarnEnabled()) {
+ logger.warn("Language not supported in Carrot2: " + lcode);
+ }
} else {
languageList.add(lang);
- logger.debug("Language loaded: " + lcode);
+ if (logger.isDebugEnabled()) {
+ logger.debug("Language loaded: " + lcode);
+ }
}
} catch (Throwable t) {
- logger.warn("Language could not be loaded: " + lcode, t);
+ if (logger.isWarnEnabled()) {
+ logger.warn("Language could not be loaded: " + lcode, t);
+ }
}
}
return new LingoLocalFilterComponent(
@@ -222,8 +228,10 @@ public class Clusterer implements OnlineClusterer, Configurable {
this.languages = conf.getStrings(CONF_PROP_LANGUAGES);
}
- logger.info("Default language: " + defaultLanguage);
- logger.info("Enabled languages: " + Arrays.asList(languages));
+ if (logger.isInfoEnabled()) {
+ logger.info("Default language: " + defaultLanguage);
+ logger.info("Enabled languages: " + Arrays.asList(languages));
+ }
initialize();
}
diff --git a/src/plugin/creativecommons/src/java/org/creativecommons/nutch/CCDeleteUnlicensedTool.java b/src/plugin/creativecommons/src/java/org/creativecommons/nutch/CCDeleteUnlicensedTool.java
index 29816e2db..361af32a5 100644
--- a/src/plugin/creativecommons/src/java/org/creativecommons/nutch/CCDeleteUnlicensedTool.java
+++ b/src/plugin/creativecommons/src/java/org/creativecommons/nutch/CCDeleteUnlicensedTool.java
@@ -95,7 +95,9 @@ public class CCDeleteUnlicensedTool {
CCDeleteUnlicensedTool dd = new CCDeleteUnlicensedTool(readers);
int count = dd.deleteUnlicensed();
- LOG.info("CC: deleted "+count+" out of "+maxDoc);
+ if (LOG.isInfoEnabled()) {
+ LOG.info("CC: deleted "+count+" out of "+maxDoc);
+ }
dd.close();
}
}
diff --git a/src/plugin/creativecommons/src/java/org/creativecommons/nutch/CCIndexingFilter.java b/src/plugin/creativecommons/src/java/org/creativecommons/nutch/CCIndexingFilter.java
index 020fb0768..dec00bd9d 100644
--- a/src/plugin/creativecommons/src/java/org/creativecommons/nutch/CCIndexingFilter.java
+++ b/src/plugin/creativecommons/src/java/org/creativecommons/nutch/CCIndexingFilter.java
@@ -56,7 +56,9 @@ public class CCIndexingFilter implements IndexingFilter {
// index the license
String licenseUrl = metadata.get(CreativeCommons.LICENSE_URL);
if (licenseUrl != null) {
- LOG.info("CC: indexing " + licenseUrl + " for: " + url.toString());
+ if (LOG.isInfoEnabled()) {
+ LOG.info("CC: indexing " + licenseUrl + " for: " + url.toString());
+ }
// add the entire license as cc:license=xxx
addFeature(doc, "license=" + licenseUrl);
@@ -99,7 +101,9 @@ public class CCIndexingFilter implements IndexingFilter {
addFeature(doc, feature);
}
} catch (MalformedURLException e) {
- LOG.warn("CC: failed to parse url: " + urlString + " : " + e);
+ if (LOG.isWarnEnabled()) {
+ LOG.warn("CC: failed to parse url: " + urlString + " : " + e);
+ }
}
}
diff --git a/src/plugin/creativecommons/src/java/org/creativecommons/nutch/CCParseFilter.java b/src/plugin/creativecommons/src/java/org/creativecommons/nutch/CCParseFilter.java
index 75614e6be..efe5f8df1 100644
--- a/src/plugin/creativecommons/src/java/org/creativecommons/nutch/CCParseFilter.java
+++ b/src/plugin/creativecommons/src/java/org/creativecommons/nutch/CCParseFilter.java
@@ -76,13 +76,17 @@ public class CCParseFilter implements HtmlParseFilter {
// add license to metadata
if (licenseUrl != null) {
- LOG.info("CC: found "+licenseUrl+" in "+licenseLocation+" of "+base);
+ if (LOG.isInfoEnabled()) {
+ LOG.info("CC: found "+licenseUrl+" in "+licenseLocation+" of "+base);
+ }
metadata.add(CreativeCommons.LICENSE_URL, licenseUrl);
metadata.add(CreativeCommons.LICENSE_LOCATION, licenseLocation);
}
if (walker.workType != null) {
- LOG.info("CC: found "+walker.workType+" in "+base);
+ if (LOG.isInfoEnabled()) {
+ LOG.info("CC: found "+walker.workType+" in "+base);
+ }
metadata.add(CreativeCommons.WORK_TYPE, walker.workType);
}
@@ -175,7 +179,9 @@ public class CCParseFilter implements HtmlParseFilter {
DocumentBuilder parser = FACTORY.newDocumentBuilder();
doc = parser.parse(new InputSource(new StringReader(comment)));
} catch (Exception e) {
- LOG.warn("CC: Failed to parse RDF in "+base+": "+e);
+ if (LOG.isWarnEnabled()) {
+ LOG.warn("CC: Failed to parse RDF in "+base+": "+e);
+ }
//e.printStackTrace();
return;
}
@@ -183,7 +189,7 @@ public class CCParseFilter implements HtmlParseFilter {
// check that root is rdf:RDF
NodeList roots = doc.getElementsByTagNameNS(RDF_NS, "RDF");
if (roots.getLength() != 1) {
- LOG.warn("CC: No RDF root in "+base);
+ if (LOG.isWarnEnabled()) { LOG.warn("CC: No RDF root in "+base); }
return;
}
Element rdf = (Element)roots.item(0);
@@ -217,7 +223,9 @@ public class CCParseFilter implements HtmlParseFilter {
// add object and predicate to metadata
// metadata.put(object, predicate);
- // LOG.info("CC: found: "+predicate+"="+object);
+ // if (LOG.isInfoEnabled()) {
+ // LOG.info("CC: found: "+predicate+"="+object);
+ // }
}
}
diff --git a/src/plugin/index-basic/src/java/org/apache/nutch/indexer/basic/BasicIndexingFilter.java b/src/plugin/index-basic/src/java/org/apache/nutch/indexer/basic/BasicIndexingFilter.java
index e3f2cce2b..be0fefac8 100644
--- a/src/plugin/index-basic/src/java/org/apache/nutch/indexer/basic/BasicIndexingFilter.java
+++ b/src/plugin/index-basic/src/java/org/apache/nutch/indexer/basic/BasicIndexingFilter.java
@@ -75,7 +75,9 @@ public class BasicIndexingFilter implements IndexingFilter {
doc.add(new Field("anchor", anchors[i], Field.Store.NO, Field.Index.TOKENIZED));
}
} catch (IOException ioe) {
- LOG.warn("BasicIndexingFilter: can't get anchors for " + url.toString());
+ if (LOG.isWarnEnabled()) {
+ LOG.warn("BasicIndexingFilter: can't get anchors for " + url.toString());
+ }
}
// title
diff --git a/src/plugin/index-more/src/java/org/apache/nutch/indexer/more/MoreIndexingFilter.java b/src/plugin/index-more/src/java/org/apache/nutch/indexer/more/MoreIndexingFilter.java
index a078dd5d5..173a908c0 100644
--- a/src/plugin/index-more/src/java/org/apache/nutch/indexer/more/MoreIndexingFilter.java
+++ b/src/plugin/index-more/src/java/org/apache/nutch/indexer/more/MoreIndexingFilter.java
@@ -155,9 +155,13 @@ public class MoreIndexingFilter implements IndexingFilter {
"dd.MM.yyyy zzz"
});
time = parsedDate.getTime();
- // LOG.warn(url + ": parsed date: " + date +" to:"+time);
+ // if (LOG.isWarnEnabled()) {
+ // LOG.warn(url + ": parsed date: " + date +" to:"+time);
+ // }
} catch (Exception e2) {
- LOG.warn(url + ": can't parse erroneous date: " + date);
+ if (LOG.isWarnEnabled()) {
+ LOG.warn(url + ": can't parse erroneous date: " + date);
+ }
}
}
return time;
@@ -194,7 +198,7 @@ public class MoreIndexingFilter implements IndexingFilter {
try {
mimeType = new MimeType(contentType);
} catch (MimeTypeException e) {
- LOG.warn(url + e.toString());
+ if (LOG.isWarnEnabled()) { LOG.warn(url + e.toString()); }
mimeType = null;
}
}
diff --git a/src/plugin/languageidentifier/src/java/org/apache/nutch/analysis/lang/HTMLLanguageParser.java b/src/plugin/languageidentifier/src/java/org/apache/nutch/analysis/lang/HTMLLanguageParser.java
index 77e9412ca..b313d1f21 100644
--- a/src/plugin/languageidentifier/src/java/org/apache/nutch/analysis/lang/HTMLLanguageParser.java
+++ b/src/plugin/languageidentifier/src/java/org/apache/nutch/analysis/lang/HTMLLanguageParser.java
@@ -68,7 +68,7 @@ public class HTMLLanguageParser implements HtmlParseFilter {
}
}
} catch (Exception e) {
- LOG.fatal(e.toString());
+ if (LOG.isFatalEnabled()) { LOG.fatal(e.toString()); }
}
}
diff --git a/src/plugin/languageidentifier/src/java/org/apache/nutch/analysis/lang/LanguageIdentifier.java b/src/plugin/languageidentifier/src/java/org/apache/nutch/analysis/lang/LanguageIdentifier.java
index 6c21f9d0d..2a28a4158 100644
--- a/src/plugin/languageidentifier/src/java/org/apache/nutch/analysis/lang/LanguageIdentifier.java
+++ b/src/plugin/languageidentifier/src/java/org/apache/nutch/analysis/lang/LanguageIdentifier.java
@@ -121,11 +121,13 @@ public class LanguageIdentifier {
p.load(this.getClass().getResourceAsStream("langmappings.properties"));
Enumeration alllanguages = p.keys();
-
- LOG.info(new StringBuffer()
- .append("Language identifier configuration [")
- .append(minLength).append("-").append(maxLength)
- .append("/").append(analyzeLength).append("]").toString());
+
+ if (LOG.isInfoEnabled()) {
+ LOG.info(new StringBuffer()
+ .append("Language identifier configuration [")
+ .append(minLength).append("-").append(maxLength)
+ .append("/").append(analyzeLength).append("]").toString());
+ }
StringBuffer list = new StringBuffer("Language identifier plugin supports:");
HashMap tmpIdx = new HashMap();
@@ -155,7 +157,7 @@ public class LanguageIdentifier {
list.append(" " + lang + "(" + ngrams.size() + ")");
is.close();
} catch (IOException e1) {
- LOG.fatal(e1.toString());
+ if (LOG.isFatalEnabled()) { LOG.fatal(e1.toString()); }
}
}
}
@@ -169,11 +171,11 @@ public class LanguageIdentifier {
ngramsIdx.put(entry.getSeq(), array);
}
}
- LOG.info(list.toString());
+ if (LOG.isInfoEnabled()) { LOG.info(list.toString()); }
// Create the suspect profile
suspect = new NGramProfile("suspect", minLength, maxLength);
} catch (Exception e) {
- LOG.fatal(e.toString());
+ if (LOG.isFatalEnabled()) { LOG.fatal(e.toString()); }
}
}
diff --git a/src/plugin/languageidentifier/src/java/org/apache/nutch/analysis/lang/NGramProfile.java b/src/plugin/languageidentifier/src/java/org/apache/nutch/analysis/lang/NGramProfile.java
index 8718ac640..778d23392 100644
--- a/src/plugin/languageidentifier/src/java/org/apache/nutch/analysis/lang/NGramProfile.java
+++ b/src/plugin/languageidentifier/src/java/org/apache/nutch/analysis/lang/NGramProfile.java
@@ -319,7 +319,7 @@ public class NGramProfile {
}
}
} catch (Exception e) {
- LOG.fatal(e.toString());
+ if (LOG.isFatalEnabled()) { LOG.fatal(e.toString()); }
}
return sum;
}
@@ -523,7 +523,7 @@ public class NGramProfile {
}
} catch (Exception e) {
- LOG.fatal("Caught an exception:" + e);
+ if (LOG.isFatalEnabled()) { LOG.fatal("Caught an exception:" + e); }
}
}
diff --git a/src/plugin/lib-http/src/java/org/apache/nutch/protocol/http/api/HttpBase.java b/src/plugin/lib-http/src/java/org/apache/nutch/protocol/http/api/HttpBase.java
index 77b27d970..9b9b06d8e 100644
--- a/src/plugin/lib-http/src/java/org/apache/nutch/protocol/http/api/HttpBase.java
+++ b/src/plugin/lib-http/src/java/org/apache/nutch/protocol/http/api/HttpBase.java
@@ -178,7 +178,9 @@ public abstract class HttpBase implements Protocol {
}
} catch (Throwable e) {
// XXX Maybe bogus: assume this is allowed.
- logger.trace("Exception checking robot rules for " + url + ": " + e);
+ if (logger.isTraceEnabled()) {
+ logger.trace("Exception checking robot rules for " + url + ": " + e);
+ }
}
String host = blockAddr(u);
@@ -231,10 +233,10 @@ public abstract class HttpBase implements Protocol {
// handle this in the higher layer.
return new ProtocolOutput(c, new ProtocolStatus(protocolStatusCode, u));
} else if (code == 400) { // bad request, mark as GONE
- logger.trace("400 Bad request: " + u);
+ if (logger.isTraceEnabled()) { logger.trace("400 Bad request: " + u); }
return new ProtocolOutput(c, new ProtocolStatus(ProtocolStatus.GONE, u));
} else if (code == 401) { // requires authorization, but no valid auth provided.
- logger.trace("401 Authentication Required");
+ if (logger.isTraceEnabled()) { logger.trace("401 Authentication Required"); }
return new ProtocolOutput(c, new ProtocolStatus(ProtocolStatus.ACCESS_DENIED, "Authentication required: "
+ urlString));
} else if (code == 404) {
@@ -392,8 +394,12 @@ public abstract class HttpBase implements Protocol {
String agentURL,
String agentEmail) {
- if ( (agentName == null) || (agentName.trim().length() == 0) )
- LOGGER.fatal("No User-Agent string set (http.agent.name)!");
+ if ( (agentName == null) || (agentName.trim().length() == 0) ) {
+ // TODO : NUTCH-258
+ if (LOGGER.isFatalEnabled()) {
+ LOGGER.fatal("No User-Agent string set (http.agent.name)!");
+ }
+ }
StringBuffer buf= new StringBuffer();
@@ -428,17 +434,20 @@ public abstract class HttpBase implements Protocol {
}
protected void logConf() {
- logger.info("http.proxy.host = " + proxyHost);
- logger.info("http.proxy.port = " + proxyPort);
- logger.info("http.timeout = " + timeout);
- logger.info("http.content.limit = " + maxContent);
- logger.info("http.agent = " + userAgent);
- logger.info("fetcher.server.delay = " + serverDelay);
- logger.info("http.max.delays = " + maxDelays);
+ if (logger.isInfoEnabled()) {
+ logger.info("http.proxy.host = " + proxyHost);
+ logger.info("http.proxy.port = " + proxyPort);
+ logger.info("http.timeout = " + timeout);
+ logger.info("http.content.limit = " + maxContent);
+ logger.info("http.agent = " + userAgent);
+ logger.info("fetcher.server.delay = " + serverDelay);
+ logger.info("http.max.delays = " + maxDelays);
+ }
}
public byte[] processGzipEncoded(byte[] compressed, URL url) throws IOException {
- LOGGER.trace("uncompressing....");
+
+ if (LOGGER.isTraceEnabled()) { LOGGER.trace("uncompressing...."); }
byte[] content = GZIPUtils.unzipBestEffort(compressed, getMaxContent());
diff --git a/src/plugin/lib-http/src/java/org/apache/nutch/protocol/http/api/RobotRulesParser.java b/src/plugin/lib-http/src/java/org/apache/nutch/protocol/http/api/RobotRulesParser.java
index 88bff4262..0ae701f66 100644
--- a/src/plugin/lib-http/src/java/org/apache/nutch/protocol/http/api/RobotRulesParser.java
+++ b/src/plugin/lib-http/src/java/org/apache/nutch/protocol/http/api/RobotRulesParser.java
@@ -206,11 +206,15 @@ public class RobotRulesParser implements Configurable {
//
if (agents.size() == 0) {
agents.add(agentName);
- LOG.fatal("No agents listed in 'http.robots.agents' property!");
+ if (LOG.isFatalEnabled()) {
+ LOG.fatal("No agents listed in 'http.robots.agents' property!");
+ }
} else if (!((String)agents.get(0)).equalsIgnoreCase(agentName)) {
agents.add(0, agentName);
- LOG.fatal("Agent we advertise (" + agentName
- + ") not listed first in 'http.robots.agents' property!");
+ if (LOG.isFatalEnabled()) {
+ LOG.fatal("Agent we advertise (" + agentName
+ + ") not listed first in 'http.robots.agents' property!");
+ }
}
setRobotNames((String[]) agents.toArray(new String[agents.size()]));
}
@@ -320,7 +324,9 @@ public class RobotRulesParser implements Configurable {
try {
path= URLDecoder.decode(path, CHARACTER_ENCODING);
} catch (Exception e) {
- LOG.warn("error parsing robots rules- can't decode path: " + path);
+ if (LOG.isWarnEnabled()) {
+ LOG.warn("error parsing robots rules- can't decode path: " + path);
+ }
}
if (path.length() == 0) { // "empty rule"
@@ -388,7 +394,7 @@ public class RobotRulesParser implements Configurable {
RobotRuleSet robotRules = (RobotRuleSet)CACHE.get(host);
if (robotRules == null) { // cache miss
- LOG.trace("cache miss " + url);
+ if (LOG.isTraceEnabled()) { LOG.trace("cache miss " + url); }
try {
Response response = http.getResponse(new URL(url, "/robots.txt"),
new CrawlDatum(), true);
@@ -400,7 +406,9 @@ public class RobotRulesParser implements Configurable {
else
robotRules = EMPTY_RULES; // use default rules
} catch (Throwable t) {
- LOG.info("Couldn't get robots.txt for " + url + ": " + t.toString());
+ if (LOG.isInfoEnabled()) {
+ LOG.info("Couldn't get robots.txt for " + url + ": " + t.toString());
+ }
robotRules = EMPTY_RULES;
}
diff --git a/src/plugin/lib-regex-filter/src/java/org/apache/nutch/urlfilter/api/RegexURLFilterBase.java b/src/plugin/lib-regex-filter/src/java/org/apache/nutch/urlfilter/api/RegexURLFilterBase.java
index 105d0b61c..1147969f7 100644
--- a/src/plugin/lib-regex-filter/src/java/org/apache/nutch/urlfilter/api/RegexURLFilterBase.java
+++ b/src/plugin/lib-regex-filter/src/java/org/apache/nutch/urlfilter/api/RegexURLFilterBase.java
@@ -134,12 +134,12 @@ public abstract class RegexURLFilterBase implements URLFilter {
String file = getRulesFile(conf);
Reader reader = conf.getConfResourceAsReader(file);
if (reader == null) {
- LOG.fatal("Can't find resource: " + file);
+ if (LOG.isFatalEnabled()) { LOG.fatal("Can't find resource: " + file); }
} else {
try {
rules = readRulesFile(reader);
} catch (IOException e) {
- LOG.fatal(e.getMessage());
+ if (LOG.isFatalEnabled()) { LOG.fatal(e.getMessage()); }
//TODO [email protected]: throw Exception? Because broken api.
throw new RuntimeException(e.getMessage(), e);
}
@@ -187,7 +187,7 @@ public abstract class RegexURLFilterBase implements URLFilter {
}
String regex = line.substring(1);
- LOG.trace("Adding rule [" + regex + "]");
+ if (LOG.isTraceEnabled()) { LOG.trace("Adding rule [" + regex + "]"); }
RegexRule rule = createRule(sign, regex);
rules.add(rule);
}
diff --git a/src/plugin/ontology/src/java/org/apache/nutch/ontology/jena/OntologyImpl.java b/src/plugin/ontology/src/java/org/apache/nutch/ontology/jena/OntologyImpl.java
index 8957bad29..223faba3a 100644
--- a/src/plugin/ontology/src/java/org/apache/nutch/ontology/jena/OntologyImpl.java
+++ b/src/plugin/ontology/src/java/org/apache/nutch/ontology/jena/OntologyImpl.java
@@ -18,6 +18,7 @@ package org.apache.nutch.ontology.jena;
import org.apache.hadoop.conf.Configuration;
import org.apache.nutch.ontology.*;
+import org.apache.nutch.util.LogUtil;
import org.apache.nutch.util.NutchConfiguration;
import com.hp.hpl.jena.ontology.Individual;
@@ -71,7 +72,7 @@ public class OntologyImpl implements org.apache.nutch.ontology.Ontology {
//only initialize all the static variables
//if first time called to this ontology constructor
if (ontology == null) {
- LOG.info( "creating new ontology");
+ if (LOG.isInfoEnabled()) { LOG.info( "creating new ontology"); }
parser = new OwlParser();
ontology = this;
}
@@ -101,14 +102,13 @@ public class OntologyImpl implements org.apache.nutch.ontology.Ontology {
private void load (Object m, String url) {
try {
- LOG.info( "reading "+url);
+ if (LOG.isInfoEnabled()) { LOG.info( "reading "+url); }
((OntModel)m).read(url);
} catch (Exception e) {
- LOG.fatal("failed on attempting to read ontology "+url);
- LOG.fatal(e.getMessage());
- StackTraceElement[] traces = e.getStackTrace();
- for (int i=0; i<traces.length; i++) {
- LOG.fatal(traces[i].toString());
+ if (LOG.isFatalEnabled()) {
+ LOG.fatal("failed on attempting to read ontology "+url);
+ LOG.fatal(e.getMessage());
+ e.printStackTrace(LogUtil.getFatalStream(LOG));
}
}
}
@@ -332,11 +332,11 @@ public class OntologyImpl implements org.apache.nutch.ontology.Ontology {
String urls = conf.get("extension.ontology.urls");
if (urls==null || urls.trim().equals("")) {
- LOG.fatal("No ontology url found.");
+ if (LOG.isFatalEnabled()) { LOG.fatal("No ontology url found."); }
return;
}
ontology.load(urls.split("\\s+"));
- LOG.info( "created new ontology");
+ if (LOG.isInfoEnabled()) { LOG.info( "created new ontology"); }
for (Iterator i = getParser().rootClasses( getModel() );
i.hasNext(); ) {
diff --git a/src/plugin/parse-html/src/java/org/apache/nutch/parse/html/HtmlParser.java b/src/plugin/parse-html/src/java/org/apache/nutch/parse/html/HtmlParser.java
index ac97c2be6..5814812ac 100644
--- a/src/plugin/parse-html/src/java/org/apache/nutch/parse/html/HtmlParser.java
+++ b/src/plugin/parse-html/src/java/org/apache/nutch/parse/html/HtmlParser.java
@@ -126,7 +126,9 @@ public class HtmlParser implements Parser {
metadata.set(Metadata.ORIGINAL_CHAR_ENCODING, encoding);
if ((encoding = StringUtil.resolveEncodingAlias(encoding)) != null) {
metadata.set(Metadata.CHAR_ENCODING_FOR_CONVERSION, encoding);
- LOG.trace(base + ": setting encoding to " + encoding);
+ if (LOG.isTraceEnabled()) {
+ LOG.trace(base + ": setting encoding to " + encoding);
+ }
}
}
@@ -137,7 +139,9 @@ public class HtmlParser implements Parser {
metadata.set(Metadata.ORIGINAL_CHAR_ENCODING, encoding);
if ((encoding = StringUtil.resolveEncodingAlias(encoding)) != null) {
metadata.set(Metadata.CHAR_ENCODING_FOR_CONVERSION, encoding);
- LOG.trace(base + ": setting encoding to " + encoding);
+ if (LOG.isTraceEnabled()) {
+ LOG.trace(base + ": setting encoding to " + encoding);
+ }
}
}
}
@@ -151,10 +155,12 @@ public class HtmlParser implements Parser {
// same share)
encoding = defaultCharEncoding;
metadata.set(Metadata.CHAR_ENCODING_FOR_CONVERSION, defaultCharEncoding);
- LOG.trace(base + ": falling back to " + defaultCharEncoding);
+ if (LOG.isTraceEnabled()) {
+ LOG.trace(base + ": falling back to " + defaultCharEncoding);
+ }
}
input.setEncoding(encoding);
- LOG.trace("Parsing...");
+ if (LOG.isTraceEnabled()) { LOG.trace("Parsing..."); }
root = parse(input);
} catch (IOException e) {
return new ParseStatus(e).getEmptyParse(getConf());
@@ -169,15 +175,17 @@ public class HtmlParser implements Parser {
// get meta directives
HTMLMetaProcessor.getMetaTags(metaTags, root, base);
- LOG.trace("Meta tags for " + base + ": " + metaTags.toString());
+ if (LOG.isTraceEnabled()) {
+ LOG.trace("Meta tags for " + base + ": " + metaTags.toString());
+ }
// check meta directives
if (!metaTags.getNoIndex()) { // okay to index
StringBuffer sb = new StringBuffer();
- LOG.trace("Getting text...");
+ if (LOG.isTraceEnabled()) { LOG.trace("Getting text..."); }
utils.getText(sb, root); // extract text
text = sb.toString();
sb.setLength(0);
- LOG.trace("Getting title...");
+ if (LOG.isTraceEnabled()) { LOG.trace("Getting title..."); }
utils.getTitle(sb, root); // extract title
title = sb.toString().trim();
}
@@ -185,10 +193,12 @@ public class HtmlParser implements Parser {
if (!metaTags.getNoFollow()) { // okay to follow links
ArrayList l = new ArrayList(); // extract outlinks
URL baseTag = utils.getBase(root);
- LOG.trace("Getting links...");
+ if (LOG.isTraceEnabled()) { LOG.trace("Getting links..."); }
utils.getOutlinks(baseTag!=null?baseTag:base, l, root);
outlinks = (Outlink[])l.toArray(new Outlink[l.size()]);
- LOG.trace("found "+outlinks.length+" outlinks in "+content.getUrl());
+ if (LOG.isTraceEnabled()) {
+ LOG.trace("found "+outlinks.length+" outlinks in "+content.getUrl());
+ }
}
if (!metaTags.getNoCache()) { // okay to cache
@@ -256,7 +266,9 @@ public class HtmlParser implements Parser {
frag = doc.createDocumentFragment();
parser.parse(input, frag);
if (!frag.hasChildNodes()) break;
- LOG.info(" - new frag, " + frag.getChildNodes().getLength() + " nodes.");
+ if (LOG.isInfoEnabled()) {
+ LOG.info(" - new frag, " + frag.getChildNodes().getLength() + " nodes.");
+ }
res.appendChild(frag);
}
} catch (Exception x) { x.printStackTrace(LogUtil.getWarnStream(LOG));};
diff --git a/src/plugin/parse-js/src/java/org/apache/nutch/parse/js/JSParseFilter.java b/src/plugin/parse-js/src/java/org/apache/nutch/parse/js/JSParseFilter.java
index 42290664c..4fb5d8107 100644
--- a/src/plugin/parse-js/src/java/org/apache/nutch/parse/js/JSParseFilter.java
+++ b/src/plugin/parse-js/src/java/org/apache/nutch/parse/js/JSParseFilter.java
@@ -87,7 +87,9 @@ public class JSParseFilter implements HtmlParseFilter, Parser {
if (i > 0) script.append('\n');
script.append(nn.item(i).getNodeValue());
}
- //LOG.info("script: language=" + lang + ", text: " + script.toString());
+ // if (LOG.isInfoEnabled()) {
+ // LOG.info("script: language=" + lang + ", text: " + script.toString());
+ // }
Outlink[] links = getJSLinks(script.toString(), base, base);
if (links != null && links.length > 0) outlinks.addAll(Arrays.asList(links));
// no other children of interest here, go one level up.
@@ -164,7 +166,7 @@ public class JSParseFilter implements HtmlParseFilter, Parser {
try {
baseURL = new URL(base);
} catch (Exception e) {
- LOG.error("getJSLinks", e);
+ if (LOG.isErrorEnabled()) { LOG.error("getJSLinks", e); }
}
try {
@@ -189,20 +191,22 @@ public class JSParseFilter implements HtmlParseFilter, Parser {
url = result.group(2);
PatternMatcherInput input1 = new PatternMatcherInput(url);
if (!matcher1.matches(input1, pattern1)) {
- //LOG.trace(" - invalid '" + url + "'");
+ //if (LOG.isTraceEnabled()) { LOG.trace(" - invalid '" + url + "'"); }
continue;
}
if (url.startsWith("www.")) {
url = "http://" + url;
} else url = new URL(baseURL, url).toString();
url = url.replaceAll("&amp;", "&");
- LOG.trace(" - outlink from JS: '" + url + "'");
+ if (LOG.isTraceEnabled()) {
+ LOG.trace(" - outlink from JS: '" + url + "'");
+ }
outlinks.add(new Outlink(url, anchor, getConf()));
}
} catch (Exception ex) {
// if it is a malformed URL we just throw it away and continue with
// extraction.
- LOG.error("getJSLinks", ex);
+ if (LOG.isErrorEnabled()) { LOG.error("getJSLinks", ex); }
}
final Outlink[] retval;
diff --git a/src/plugin/parse-mspowerpoint/src/java/org/apache/nutch/parse/mspowerpoint/ContentReaderListener.java b/src/plugin/parse-mspowerpoint/src/java/org/apache/nutch/parse/mspowerpoint/ContentReaderListener.java
index 6cd0db1e4..f7815b963 100644
--- a/src/plugin/parse-mspowerpoint/src/java/org/apache/nutch/parse/mspowerpoint/ContentReaderListener.java
+++ b/src/plugin/parse-mspowerpoint/src/java/org/apache/nutch/parse/mspowerpoint/ContentReaderListener.java
@@ -65,8 +65,10 @@ class ContentReaderListener implements POIFSReaderListener {
if (event == null || event.getName() == null
|| !event.getName().startsWith(PPTConstants.POWERPOINT_DOCUMENT)) {
- LOG.warn("Stream not processed. It is not a PowerPoint document: : "
- + event.getName());
+ if (LOG.isWarnEnabled()) {
+ LOG.warn("Stream not processed. It is not a PowerPoint document: : "
+ + event.getName());
+ }
return;
}
@@ -108,14 +110,22 @@ class ContentReaderListener implements POIFSReaderListener {
containerTextBox = extractTextBoxes(containerTextBox, offset,
pptdata, offsetPD);
} else if (PPTConstants.PPT_ATOM_DRAWINGGROUP == type) {
- // LOG.trace("PPT_DRAWINGGROUP_ATOM ignored: " + type);
+ // if (LOG.isTraceEnabled()) {
+ // LOG.trace("PPT_DRAWINGGROUP_ATOM ignored: " + type);
+ // }
} else if (PPTConstants.PPT_ATOM_TEXTBYTE == type) {
- // LOG.trace("PPT_TEXTBYTE_ATOM ignored: " + type);
+ // if (LOG.isTraceEnabled()) {
+ // LOG.trace("PPT_TEXTBYTE_ATOM ignored: " + type);
+ // }
} else if (PPTConstants.PPT_ATOM_TEXTCHAR == type) {
- // LOG.trace("PPT_TEXTCHAR_ATOM ignored: " + type);
+ // if (LOG.isTraceEnabled()) {
+ // LOG.trace("PPT_TEXTCHAR_ATOM ignored: " + type);
+ // }
} else {
// no action
- // LOG.trace("type not handled: " + type);
+ // if (LOG.isTraceEnabled()) {
+ // LOG.trace("type not handled: " + type);
+ // }
}
}
@@ -123,7 +133,7 @@ class ContentReaderListener implements POIFSReaderListener {
offsetPD);
if (slides.size() == 0) {
- LOG.info("No slides extracted!");
+ if (LOG.isInfoEnabled()) { LOG.info("No slides extracted!"); }
} else {
Slide slide = (Slide) slides.get(slides.size() - 1);
@@ -158,7 +168,7 @@ class ContentReaderListener implements POIFSReaderListener {
}
} catch (Throwable ex) {
// because of not killing complete crawling all Throwables are catched.
- LOG.error("processPOIFSReaderEvent", ex);
+ if (LOG.isErrorEnabled()) { LOG.error("processPOIFSReaderEvent", ex); }
}
}
@@ -205,7 +215,7 @@ class ContentReaderListener implements POIFSReaderListener {
if (currentID == PPTConstants.PPT_MASTERSLIDE) {
// Ignore Master Slide objects
- LOG.trace("Ignore master slide.");
+ if (LOG.isTraceEnabled()) { LOG.trace("Ignore master slide."); }
i++;
continue;
}
@@ -226,8 +236,10 @@ class ContentReaderListener implements POIFSReaderListener {
*/
if ((offsetPD - 20) != recordSize) {
// TODO something wrong? Probably an OLE-Object, which we ignore.
- LOG.debug("offsetPD - 20=" + (offsetPD - 20) + " recordsize="
- + recordSize);
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("offsetPD - 20=" + (offsetPD - 20) + " recordsize="
+ + recordSize);
+ }
} else {
for (int startPos = i + 8; startPos < offsetPD - 20
&& startPos < recordSize; startPos++) { // && startPos <
@@ -290,22 +302,24 @@ class ContentReaderListener implements POIFSReaderListener {
} else {
// ignored
- // LOG.trace("Ignored atom type: " + type);
+ // if (LOG.isTraceEnabled()) {
+ // LOG.trace("Ignored atom type: " + type);
+ // }
}
} catch (Throwable e) {
- LOG.error("extractTextBoxes", e);
+ if (LOG.isErrorEnabled()) { LOG.error("extractTextBoxes", e); }
break;
}
}
}
} else {
- /*
- * Record type is ignored
- */
- // LOG.trace("Ignored record type: " + type);
+ // Record type is ignored
+ // if (LOG.isTraceEnabled()) {
+ // LOG.trace("Ignored record type: " + type);
+ // }
}
} catch (Throwable ee) {
- LOG.error("extractClientTextBoxes", ee);
+ if (LOG.isErrorEnabled()) { LOG.error("extractClientTextBoxes", ee); }
break;
}
}
@@ -355,8 +369,8 @@ class ContentReaderListener implements POIFSReaderListener {
byte value = pptdata[(int) ii + 2];
outStream.write(value);
} catch (ArrayIndexOutOfBoundsException ex) {
- LOG.trace("size=" + pptdata.length);
- LOG.error("extractSlides", ex);
+ if (LOG.isTraceEnabled()) { LOG.trace("size=" + pptdata.length); }
+ if (LOG.isErrorEnabled()) { LOG.error("extractSlides", ex); }
}
}
@@ -401,11 +415,13 @@ class ContentReaderListener implements POIFSReaderListener {
/*
* Diagram records are ignored
*/
- LOG.trace("Drawing Groups are ignored.");
+ if (LOG.isTraceEnabled()) { LOG.trace("Drawing Groups are ignored."); }
break;
} else {
// ignored
- // LOG.trace("Unhandled atomType: " + atomType);
+ // if (LOG.isTraceEnabled()) {
+ // LOG.trace("Unhandled atomType: " + atomType);
+ // }
}
}
diff --git a/src/plugin/parse-mspowerpoint/src/java/org/apache/nutch/parse/mspowerpoint/PPTExtractor.java b/src/plugin/parse-mspowerpoint/src/java/org/apache/nutch/parse/mspowerpoint/PPTExtractor.java
index b5cbeb585..97d86dd70 100644
--- a/src/plugin/parse-mspowerpoint/src/java/org/apache/nutch/parse/mspowerpoint/PPTExtractor.java
+++ b/src/plugin/parse-mspowerpoint/src/java/org/apache/nutch/parse/mspowerpoint/PPTExtractor.java
@@ -47,7 +47,7 @@ class PPTExtractor extends MSExtractor {
input.reset();
if (input.available() > 0) {
this.reader.read(input);
- } else {
+ } else if (LOG.isWarnEnabled()) {
LOG.warn("Input <=0 :" + input.available());
}
return (this.text != null) ? text.toString() : null;
diff --git a/src/plugin/parse-pdf/src/java/org/apache/nutch/parse/pdf/PdfParser.java b/src/plugin/parse-pdf/src/java/org/apache/nutch/parse/pdf/PdfParser.java
index aba318996..010d4db70 100644
--- a/src/plugin/parse-pdf/src/java/org/apache/nutch/parse/pdf/PdfParser.java
+++ b/src/plugin/parse-pdf/src/java/org/apache/nutch/parse/pdf/PdfParser.java
@@ -125,8 +125,10 @@ public class PdfParser implements Parser {
return new ParseStatus(ParseStatus.FAILED,
"Can't decrypt document - invalid password. " + e).getEmptyParse(getConf());
} catch (Exception e) { // run time exception
- LOG.warn("General exception in PDF parser: "+e.getMessage());
- e.printStackTrace(LogUtil.getWarnStream(LOG));
+ if (LOG.isWarnEnabled()) {
+ LOG.warn("General exception in PDF parser: "+e.getMessage());
+ e.printStackTrace(LogUtil.getWarnStream(LOG));
+ }
return new ParseStatus(ParseStatus.FAILED,
"Can't be handled as pdf document. " + e).getEmptyParse(getConf());
} finally {
diff --git a/src/plugin/parse-rss/src/java/org/apache/nutch/parse/rss/RSSParser.java b/src/plugin/parse-rss/src/java/org/apache/nutch/parse/rss/RSSParser.java
index 2f4a16644..f29c858f7 100644
--- a/src/plugin/parse-rss/src/java/org/apache/nutch/parse/rss/RSSParser.java
+++ b/src/plugin/parse-rss/src/java/org/apache/nutch/parse/rss/RSSParser.java
@@ -95,8 +95,10 @@ public class RSSParser implements Parser {
theRSSChannels = ((FeedParserListenerImpl) listener).getChannels();
} catch (Exception e) { // run time exception
- e.printStackTrace(LogUtil.getWarnStream(LOG));
- LOG.trace("nutch:parse-rss:RSSParser Exception: " + e.getMessage());
+ if (LOG.isWarnEnabled()) {
+ e.printStackTrace(LogUtil.getWarnStream(LOG));
+ LOG.warn("nutch:parse-rss:RSSParser Exception: " + e.getMessage());
+ }
return new ParseStatus(ParseStatus.FAILED,
"Can't be handled as rss document. " + e).getEmptyParse(getConf());
}
@@ -130,10 +132,11 @@ public class RSSParser implements Parser {
theOutlinks.add(new Outlink(r.getLink(), "", getConf()));
}
} catch (MalformedURLException e) {
- LOG.info("nutch:parse-rss:RSSParser Exception: MalformedURL: "
- + r.getLink()
- + ": Attempting to continue processing outlinks");
- e.printStackTrace(LogUtil.getWarnStream(LOG));
+ if (LOG.isWarnEnabled()) {
+ LOG.warn("MalformedURL: " + r.getLink());
+ LOG.warn("Attempting to continue processing outlinks");
+ e.printStackTrace(LogUtil.getWarnStream(LOG));
+ }
continue;
}
}
@@ -160,10 +163,11 @@ public class RSSParser implements Parser {
theOutlinks.add(new Outlink(whichLink, "", getConf()));
}
} catch (MalformedURLException e) {
- LOG.info("nutch:parse-rss:RSSParser Exception: MalformedURL: "
- + whichLink
- + ": Attempting to continue processing outlinks");
- e.printStackTrace(LogUtil.getWarnStream(LOG));
+ if (LOG.isWarnEnabled()) {
+ LOG.warn("MalformedURL: " + whichLink);
+ LOG.warn("Attempting to continue processing outlinks");
+ e.printStackTrace(LogUtil.getWarnStream(LOG));
+ }
continue;
}
}
@@ -172,18 +176,24 @@ public class RSSParser implements Parser {
}
- LOG.trace("nutch:parse-rss:getParse:indexText=" + indexText);
- LOG.trace("nutch:parse-rss:getParse:contentTitle=" + contentTitle);
+ if (LOG.isTraceEnabled()) {
+ LOG.trace("nutch:parse-rss:getParse:indexText=" + indexText);
+ LOG.trace("nutch:parse-rss:getParse:contentTitle=" + contentTitle);
+ }
- } else {
+ } else if (LOG.isTraceEnabled()) {
LOG.trace("nutch:parse-rss:Error:getParse: No RSS Channels recorded!");
}
// format the outlinks
Outlink[] outlinks = (Outlink[]) theOutlinks.toArray(new Outlink[theOutlinks.size()]);
- LOG.trace("nutch:parse-rss:getParse:found " + outlinks.length + " outlinks");
- // LOG.info("Outlinks: "+outlinks);
+ if (LOG.isTraceEnabled()) {
+ LOG.trace("nutch:parse-rss:getParse:found " + outlinks.length + " outlinks");
+ }
+ // if (LOG.isInfoEnabled()) {
+ // LOG.info("Outlinks: "+outlinks);
+ // }
ParseData parseData = new ParseData(ParseStatus.STATUS_SUCCESS,
contentTitle.toString(), outlinks, content.getMetadata());
diff --git a/src/plugin/parse-zip/src/java/org/apache/nutch/parse/zip/ZipParser.java b/src/plugin/parse-zip/src/java/org/apache/nutch/parse/zip/ZipParser.java
index bb0323e39..6bbc0c08a 100644
--- a/src/plugin/parse-zip/src/java/org/apache/nutch/parse/zip/ZipParser.java
+++ b/src/plugin/parse-zip/src/java/org/apache/nutch/parse/zip/ZipParser.java
@@ -62,7 +62,7 @@ public class ZipParser implements Parser {
try {
final String contentLen = content.getMetadata().get(Response.CONTENT_LENGTH);
final int len = Integer.parseInt(contentLen);
- LOG.debug("ziplen: " + len);
+ if (LOG.isDebugEnabled()) { LOG.debug("ziplen: " + len); }
final byte[] contentInBytes = content.getContent();
final ByteArrayInputStream bainput = new ByteArrayInputStream(
contentInBytes);
@@ -101,7 +101,7 @@ public class ZipParser implements Parser {
content.getMetadata());
parseData.setConf(this.conf);
- LOG.trace("Zip file parsed sucessfully !!");
+ if (LOG.isTraceEnabled()) { LOG.trace("Zip file parsed sucessfully !!"); }
return new ParseImpl(resultText, parseData);
}
diff --git a/src/plugin/parse-zip/src/java/org/apache/nutch/parse/zip/ZipTextExtractor.java b/src/plugin/parse-zip/src/java/org/apache/nutch/parse/zip/ZipTextExtractor.java
index 06a55db07..c85f8eaea 100644
--- a/src/plugin/parse-zip/src/java/org/apache/nutch/parse/zip/ZipTextExtractor.java
+++ b/src/plugin/parse-zip/src/java/org/apache/nutch/parse/zip/ZipTextExtractor.java
@@ -106,8 +106,9 @@ private Configuration conf;
resultText += entry.getName() + " " + parse.getText() + " ";
} catch (ParseException e) {
-
- LOG.info("fetch okay, but can't parse " + fname + ", reason: " + e.getMessage());
+ if (LOG.isInfoEnabled()) {
+ LOG.info("fetch okay, but can't parse " + fname + ", reason: " + e.getMessage());
+ }
}
}
}
diff --git a/src/plugin/protocol-file/src/java/org/apache/nutch/protocol/file/FileResponse.java b/src/plugin/protocol-file/src/java/org/apache/nutch/protocol/file/FileResponse.java
index 8f9bc7f86..49cdd7f25 100644
--- a/src/plugin/protocol-file/src/java/org/apache/nutch/protocol/file/FileResponse.java
+++ b/src/plugin/protocol-file/src/java/org/apache/nutch/protocol/file/FileResponse.java
@@ -101,7 +101,9 @@ public class FileResponse {
}
if (url.getPath() != url.getFile()) {
- File.LOG.warn("url.getPath() != url.getFile(): " + url);
+ if (File.LOG.isWarnEnabled()) {
+ File.LOG.warn("url.getPath() != url.getFile(): " + url);
+ }
}
String path = "".equals(url.getPath()) ? "/" : url.getPath();
@@ -179,8 +181,11 @@ public class FileResponse {
&& (n = is.read(this.content, offset, len-offset)) >= 0) {
offset += n;
}
- if (offset < len) // keep whatever already have, but issue a warning
- File.LOG.warn("not enough bytes read from file: "+f.getPath());
+ if (offset < len) { // keep whatever already have, but issue a warning
+ if (File.LOG.isWarnEnabled()) {
+ File.LOG.warn("not enough bytes read from file: "+f.getPath());
+ }
+ }
is.close();
// set headers
diff --git a/src/plugin/protocol-ftp/src/java/org/apache/nutch/protocol/ftp/FtpResponse.java b/src/plugin/protocol-ftp/src/java/org/apache/nutch/protocol/ftp/FtpResponse.java
index 76b62df38..34b00b008 100644
--- a/src/plugin/protocol-ftp/src/java/org/apache/nutch/protocol/ftp/FtpResponse.java
+++ b/src/plugin/protocol-ftp/src/java/org/apache/nutch/protocol/ftp/FtpResponse.java
@@ -28,6 +28,7 @@ import org.apache.nutch.crawl.CrawlDatum;
import org.apache.nutch.protocol.Content;
import org.apache.nutch.metadata.Metadata;
import org.apache.nutch.net.protocols.Response;
+import org.apache.nutch.util.LogUtil;
import org.apache.hadoop.conf.Configuration;
@@ -92,15 +93,20 @@ public class FtpResponse {
if (!"ftp".equals(url.getProtocol()))
throw new FtpException("Not a ftp url:" + url);
- if (url.getPath() != url.getFile())
- Ftp.LOG.warn("url.getPath() != url.getFile(): " + url);
+ if (url.getPath() != url.getFile()) {
+ if (Ftp.LOG.isWarnEnabled()) {
+ Ftp.LOG.warn("url.getPath() != url.getFile(): " + url);
+ }
+ }
String path = "".equals(url.getPath()) ? "/" : url.getPath();
try {
if (ftp.followTalk) {
- Ftp.LOG.info("fetching "+url);
+ if (Ftp.LOG.isInfoEnabled()) {
+ Ftp.LOG.info("fetching "+url);
+ }
} else {
if (Ftp.LOG.isTraceEnabled()) {
Ftp.LOG.trace("fetching "+url);
@@ -113,14 +119,17 @@ public class FtpResponse {
// should start anew.
if (ftp.client != null && ftp.keepConnection
&& ftp.renewalTime < System.currentTimeMillis()) {
- Ftp.LOG.info("delete client because idled too long");
+ if (Ftp.LOG.isInfoEnabled()) {
+ Ftp.LOG.info("delete client because idled too long");
+ }
ftp.client = null;
}
// start anew if needed
if (ftp.client == null) {
- if (ftp.followTalk)
+ if ((ftp.followTalk) && (Ftp.LOG.isInfoEnabled())) {
Ftp.LOG.info("start client");
+ }
// the real client
ftp.client = new Client();
// when to renew, take the lesser
@@ -142,9 +151,10 @@ public class FtpResponse {
if (ftp.client.isConnected()) {
InetAddress remoteAddress = ftp.client.getRemoteAddress();
if (!addr.equals(remoteAddress)) {
- if (ftp.followTalk)
+ if ((ftp.followTalk) && (Ftp.LOG.isInfoEnabled())) {
Ftp.LOG.info("disconnect from "+remoteAddress
+" before connect to "+addr);
+ }
// quit from current site
ftp.client.logout();
ftp.client.disconnect();
@@ -154,20 +164,24 @@ public class FtpResponse {
// connect to current site if needed
if (!ftp.client.isConnected()) {
- if (ftp.followTalk)
+ if ((ftp.followTalk) && (Ftp.LOG.isInfoEnabled())) {
Ftp.LOG.info("connect to "+addr);
+ }
ftp.client.connect(addr);
if (!FTPReply.isPositiveCompletion(ftp.client.getReplyCode())) {
ftp.client.disconnect();
- Ftp.LOG.warn("ftp.client.connect() failed: "
- + addr + " " + ftp.client.getReplyString());
+ if (Ftp.LOG.isWarnEnabled()) {
+ Ftp.LOG.warn("ftp.client.connect() failed: "
+ + addr + " " + ftp.client.getReplyString());
+ }
this.code = 500; // http Internal Server Error
return;
}
- if (ftp.followTalk)
+ if ((ftp.followTalk) && (Ftp.LOG.isInfoEnabled())) {
Ftp.LOG.info("log into "+addr);
+ }
if (!ftp.client.login(ftp.userName, ftp.passWord)) {
// login failed.
@@ -176,7 +190,9 @@ public class FtpResponse {
// but throw exception, which then will be handled by caller
// (not dealt with here at all) .
ftp.client.disconnect();
- Ftp.LOG.warn("ftp.client.login() failed: "+addr);
+ if (Ftp.LOG.isWarnEnabled()) {
+ Ftp.LOG.warn("ftp.client.login() failed: "+addr);
+ }
this.code = 401; // http Unauthorized
return;
}
@@ -185,13 +201,16 @@ public class FtpResponse {
if (!ftp.client.setFileType(FTP.BINARY_FILE_TYPE)) {
ftp.client.logout();
ftp.client.disconnect();
- Ftp.LOG.warn("ftp.client.setFileType() failed: "+addr);
+ if (Ftp.LOG.isWarnEnabled()) {
+ Ftp.LOG.warn("ftp.client.setFileType() failed: "+addr);
+ }
this.code = 500; // http Internal Server Error
return;
}
- if (ftp.followTalk)
+ if ((ftp.followTalk) && (Ftp.LOG.isInfoEnabled())) {
Ftp.LOG.info("set parser for "+addr);
+ }
// SYST is valid only after login
try {
@@ -203,18 +222,24 @@ public class FtpResponse {
ftp.parser = (new DefaultFTPFileEntryParserFactory())
.createFileEntryParser(parserKey);
} catch (FtpExceptionBadSystResponse e) {
- Ftp.LOG.warn("ftp.client.getSystemName() failed: "+addr+" "+e);
+ if (Ftp.LOG.isWarnEnabled()) {
+ Ftp.LOG.warn("ftp.client.getSystemName() failed: "+addr+" "+e);
+ }
ftp.parser = null;
} catch (ParserInitializationException e) {
// ParserInitializationException is RuntimeException defined in
// org.apache.commons.net.ftp.parser.ParserInitializationException
- Ftp.LOG.warn("createFileEntryParser() failed. "+addr+" "+e);
+ if (Ftp.LOG.isWarnEnabled()) {
+ Ftp.LOG.warn("createFileEntryParser() failed. "+addr+" "+e);
+ }
ftp.parser = null;
} finally {
if (ftp.parser == null) {
// do not log as severe, otherwise
// FetcherThread/RequestScheduler will abort
- Ftp.LOG.warn("ftp.parser is null: "+addr);
+ if (Ftp.LOG.isWarnEnabled()) {
+ Ftp.LOG.warn("ftp.parser is null: "+addr);
+ }
ftp.client.logout();
ftp.client.disconnect();
this.code = 500; // http Internal Server Error
@@ -223,8 +248,9 @@ public class FtpResponse {
}
} else {
- if (ftp.followTalk)
+ if ((ftp.followTalk) && (Ftp.LOG.isInfoEnabled())) {
Ftp.LOG.info("use existing connection");
+ }
}
this.content = null;
@@ -239,30 +265,32 @@ public class FtpResponse {
if (ftp.client != null && ftp.keepConnection) {
ftp.renewalTime = System.currentTimeMillis()
+ ((ftp.timeout<ftp.serverTimeout) ? ftp.timeout : ftp.serverTimeout);
- if (ftp.followTalk)
+ if ((ftp.followTalk) && (Ftp.LOG.isInfoEnabled())) {
Ftp.LOG.info("reset renewalTime to "
+ftp.httpDateFormat.toString(ftp.renewalTime));
+ }
}
// getDirAsHttpResponse() or getFileAsHttpResponse() above
// may have deleted ftp.client
if (ftp.client != null && !ftp.keepConnection) {
- if (ftp.followTalk)
+ if ((ftp.followTalk) && (Ftp.LOG.isInfoEnabled())) {
Ftp.LOG.info("disconnect from "+addr);
+ }
ftp.client.logout();
ftp.client.disconnect();
}
} catch (Exception e) {
- ftp.LOG.warn(""+e);
- StackTraceElement stes[] = e.getStackTrace();
- for (int i=0; i<stes.length; i++) {
- ftp.LOG.warn(" "+stes[i].toString());
+ if (ftp.LOG.isWarnEnabled()) {
+ ftp.LOG.warn(""+e);
+ e.printStackTrace(LogUtil.getWarnStream(ftp.LOG));
}
// for any un-foreseen exception (run time exception or not),
// do ultimate clean and leave ftp.client for garbage collection
- if (ftp.followTalk)
+ if ((ftp.followTalk) && (Ftp.LOG.isInfoEnabled())) {
Ftp.LOG.info("delete client due to exception");
+ }
ftp.client = null;
// or do explicit garbage collection?
// System.gc();
@@ -313,17 +341,20 @@ public class FtpResponse {
// control connection is off, clean up
// ftp.client.disconnect();
- if (ftp.followTalk)
+ if ((ftp.followTalk) && (Ftp.LOG.isInfoEnabled())) {
Ftp.LOG.info("delete client because server cut off control channel: "+e);
+ }
ftp.client = null;
// in case this FtpExceptionControlClosedByForcedDataClose is
// thrown by retrieveList() (not retrieveFile()) above,
if (os == null) { // indicating throwing by retrieveList()
//throw new FtpException("fail to get attibutes: "+path);
- Ftp.LOG.warn(
- "Please try larger maxContentLength for ftp.client.retrieveList(). "
- + e);
+ if (Ftp.LOG.isWarnEnabled()) {
+ Ftp.LOG.warn(
+ "Please try larger maxContentLength for ftp.client.retrieveList(). "
+ + e);
+ }
// in a way, this is our request fault
this.code = 400; // http Bad request
return;
@@ -360,10 +391,12 @@ public class FtpResponse {
} catch (FtpExceptionUnknownForcedDataClose e) {
// Please note control channel is still live.
// in a way, this is our request fault
- Ftp.LOG.warn(
- "Unrecognized reply after forced close of data channel. "
- + "If this is acceptable, please modify Client.java accordingly. "
- + e);
+ if (Ftp.LOG.isWarnEnabled()) {
+ Ftp.LOG.warn(
+ "Unrecognized reply after forced close of data channel. "
+ + "If this is acceptable, please modify Client.java accordingly. "
+ + e);
+ }
this.code = 400; // http Bad Request
}
@@ -403,8 +436,9 @@ public class FtpResponse {
// control connection is off, clean up
// ftp.client.disconnect();
- if (ftp.followTalk)
+ if ((ftp.followTalk) && (Ftp.LOG.isInfoEnabled())) {
Ftp.LOG.info("delete client because server cut off control channel: "+e);
+ }
ftp.client = null;
this.content = list2html(list, path, "/".equals(path) ? false : true);
@@ -424,13 +458,15 @@ public class FtpResponse {
} catch (FtpExceptionUnknownForcedDataClose e) {
// Please note control channel is still live.
// in a way, this is our request fault
- Ftp.LOG.warn(
- "Unrecognized reply after forced close of data channel. "
- + "If this is acceptable, please modify Client.java accordingly. "
- + e);
+ if (Ftp.LOG.isWarnEnabled()) {
+ Ftp.LOG.warn(
+ "Unrecognized reply after forced close of data channel. "
+ + "If this is acceptable, please modify Client.java accordingly. "
+ + e);
+ }
this.code = 400; // http Bad Request
} catch (FtpExceptionCanNotHaveDataConnection e) {
- Ftp.LOG.warn(""+ e);
+ if (Ftp.LOG.isWarnEnabled()) { Ftp.LOG.warn(""+ e); }
this.code = 500; // http Iternal Server Error
}
diff --git a/src/plugin/protocol-ftp/src/java/org/apache/nutch/protocol/ftp/PrintCommandListener.java b/src/plugin/protocol-ftp/src/java/org/apache/nutch/protocol/ftp/PrintCommandListener.java
index c83a9f872..19358f073 100644
--- a/src/plugin/protocol-ftp/src/java/org/apache/nutch/protocol/ftp/PrintCommandListener.java
+++ b/src/plugin/protocol-ftp/src/java/org/apache/nutch/protocol/ftp/PrintCommandListener.java
@@ -43,7 +43,9 @@ public class PrintCommandListener implements ProtocolCommandListener
try {
__logIt(event);
} catch (IOException e) {
- __logger.info("PrintCommandListener.protocolCommandSent(): "+e);
+ if (__logger.isInfoEnabled()) {
+ __logger.info("PrintCommandListener.protocolCommandSent(): "+e);
+ }
}
}
@@ -51,11 +53,14 @@ public class PrintCommandListener implements ProtocolCommandListener
try {
__logIt(event);
} catch (IOException e) {
- __logger.info("PrintCommandListener.protocolReplyReceived(): "+e);
+ if (__logger.isInfoEnabled()) {
+ __logger.info("PrintCommandListener.protocolReplyReceived(): "+e);
+ }
}
}
private void __logIt(ProtocolCommandEvent event) throws IOException {
+ if (!__logger.isInfoEnabled()) { return; }
BufferedReader br =
new BufferedReader(new StringReader(event.getMessage()));
String line;
diff --git a/src/plugin/protocol-http/src/java/org/apache/nutch/protocol/http/HttpResponse.java b/src/plugin/protocol-http/src/java/org/apache/nutch/protocol/http/HttpResponse.java
index 9b42a06a4..0679420c0 100644
--- a/src/plugin/protocol-http/src/java/org/apache/nutch/protocol/http/HttpResponse.java
+++ b/src/plugin/protocol-http/src/java/org/apache/nutch/protocol/http/HttpResponse.java
@@ -114,7 +114,7 @@ public class HttpResponse implements Response {
String userAgent = http.getUserAgent();
if ((userAgent == null) || (userAgent.length() == 0)) {
- Http.LOG.fatal("User-agent is not set!");
+ if (Http.LOG.isFatalEnabled()) { Http.LOG.fatal("User-agent is not set!"); }
} else {
reqStr.append("User-Agent: ");
reqStr.append(userAgent);
@@ -230,19 +230,21 @@ public class HttpResponse implements Response {
ByteArrayOutputStream out = new ByteArrayOutputStream(Http.BUFFER_SIZE);
while (!doneChunks) {
- Http.LOG.trace("Http: starting chunk");
+ if (Http.LOG.isTraceEnabled()) {
+ Http.LOG.trace("Http: starting chunk");
+ }
readLine(in, line, false);
String chunkLenStr;
- // LOG.trace("chunk-header: '" + line + "'");
+ // if (LOG.isTraceEnabled()) { LOG.trace("chunk-header: '" + line + "'"); }
int pos= line.indexOf(";");
if (pos < 0) {
chunkLenStr= line.toString();
} else {
chunkLenStr= line.substring(0, pos);
- // LOG.trace("got chunk-ext: " + line.substring(pos+1));
+ // if (LOG.isTraceEnabled()) { LOG.trace("got chunk-ext: " + line.substring(pos+1)); }
}
chunkLenStr= chunkLenStr.trim();
int chunkLen;
@@ -276,7 +278,7 @@ public class HttpResponse implements Response {
// DANGER!!! Will printed GZIPed stuff right to your
// terminal!
- // LOG.trace("read: " + new String(bytes, 0, len));
+ // if (LOG.isTraceEnabled()) { LOG.trace("read: " + new String(bytes, 0, len)); }
out.write(bytes, 0, len);
chunkBytesRead+= len;
diff --git a/src/plugin/protocol-httpclient/src/java/org/apache/nutch/protocol/httpclient/DummySSLProtocolSocketFactory.java b/src/plugin/protocol-httpclient/src/java/org/apache/nutch/protocol/httpclient/DummySSLProtocolSocketFactory.java
index fc1af2e63..cfb64afc0 100644
--- a/src/plugin/protocol-httpclient/src/java/org/apache/nutch/protocol/httpclient/DummySSLProtocolSocketFactory.java
+++ b/src/plugin/protocol-httpclient/src/java/org/apache/nutch/protocol/httpclient/DummySSLProtocolSocketFactory.java
@@ -45,7 +45,7 @@ public class DummySSLProtocolSocketFactory implements ProtocolSocketFactory {
context.init(null, new TrustManager[] { new DummyX509TrustManager(null) }, null);
return context;
} catch (Exception e) {
- LOG.error(e.getMessage(), e);
+ if (LOG.isErrorEnabled()) { LOG.error(e.getMessage(), e); }
throw new HttpClientError(e.toString());
}
}
diff --git a/src/plugin/protocol-httpclient/src/java/org/apache/nutch/protocol/httpclient/Http.java b/src/plugin/protocol-httpclient/src/java/org/apache/nutch/protocol/httpclient/Http.java
index 15b02f855..ac66d5df7 100644
--- a/src/plugin/protocol-httpclient/src/java/org/apache/nutch/protocol/httpclient/Http.java
+++ b/src/plugin/protocol-httpclient/src/java/org/apache/nutch/protocol/httpclient/Http.java
@@ -135,8 +135,10 @@ public class Http extends HttpBase {
Credentials ntCreds = new NTCredentials(ntlmUsername, ntlmPassword, ntlmHost, ntlmDomain);
client.getState().setCredentials(new AuthScope(ntlmHost, AuthScope.ANY_PORT), ntCreds);
- LOG.info("Added NTLM credentials for " + ntlmUsername);
+ if (LOG.isInfoEnabled()) {
+ LOG.info("Added NTLM credentials for " + ntlmUsername);
+ }
}
- LOG.info("Configured Client");
+ if (LOG.isInfoEnabled()) { LOG.info("Configured Client"); }
}
}
diff --git a/src/plugin/protocol-httpclient/src/java/org/apache/nutch/protocol/httpclient/HttpAuthenticationFactory.java b/src/plugin/protocol-httpclient/src/java/org/apache/nutch/protocol/httpclient/HttpAuthenticationFactory.java
index 710191adf..c9f3197a6 100644
--- a/src/plugin/protocol-httpclient/src/java/org/apache/nutch/protocol/httpclient/HttpAuthenticationFactory.java
+++ b/src/plugin/protocol-httpclient/src/java/org/apache/nutch/protocol/httpclient/HttpAuthenticationFactory.java
@@ -99,7 +99,9 @@ public class HttpAuthenticationFactory implements Configurable {
}
}
if (challenge == null) {
- LOG.trace("Authentication challenge is null");
+ if (LOG.isTraceEnabled()) {
+ LOG.trace("Authentication challenge is null");
+ }
return null;
}
@@ -110,8 +112,10 @@ public class HttpAuthenticationFactory implements Configurable {
if (challengeString.equals("NTLM")) {
challengeString="Basic realm=techweb";
}
-
- LOG.trace("Checking challengeString=" + challengeString);
+
+ if (LOG.isTraceEnabled()) {
+ LOG.trace("Checking challengeString=" + challengeString);
+ }
auth = HttpBasicAuthentication.getAuthentication(challengeString, conf);
if (auth != null) return auth;
diff --git a/src/plugin/protocol-httpclient/src/java/org/apache/nutch/protocol/httpclient/HttpBasicAuthentication.java b/src/plugin/protocol-httpclient/src/java/org/apache/nutch/protocol/httpclient/HttpBasicAuthentication.java
index 4d62ab2c4..0c77111d0 100644
--- a/src/plugin/protocol-httpclient/src/java/org/apache/nutch/protocol/httpclient/HttpBasicAuthentication.java
+++ b/src/plugin/protocol-httpclient/src/java/org/apache/nutch/protocol/httpclient/HttpBasicAuthentication.java
@@ -57,14 +57,17 @@ public class HttpBasicAuthentication implements HttpAuthentication, Configurable
setConf(conf);
this.challenge = challenge;
- LOG.trace("BasicAuthentication challenge is " + challenge);
credentials = new ArrayList();
String username = this.conf.get("http.auth.basic." + challenge + ".user");
- LOG.trace("BasicAuthentication username=" + username);
String password = this.conf.get("http.auth.basic." + challenge + ".password");
- LOG.trace("BasicAuthentication password=" + password);
+ if (LOG.isTraceEnabled()) {
+ LOG.trace("BasicAuthentication challenge is " + challenge);
+ LOG.trace("BasicAuthentication username=" + username);
+ LOG.trace("BasicAuthentication password=" + password);
+ }
+
if (username == null) {
throw new HttpAuthenticationException("Username for " + challenge + " is null");
}
@@ -75,7 +78,9 @@ public class HttpBasicAuthentication implements HttpAuthentication, Configurable
byte[] credBytes = (username + ":" + password).getBytes();
credentials.add("Authorization: Basic " + new String(Base64.encodeBase64(credBytes)));
- LOG.trace("Basic credentials: " + credentials);
+ if (LOG.isTraceEnabled()) {
+ LOG.trace("Basic credentials: " + credentials);
+ }
}
@@ -145,7 +150,9 @@ public class HttpBasicAuthentication implements HttpAuthentication, Configurable
try {
newAuth = new HttpBasicAuthentication(realm, conf);
} catch (HttpAuthenticationException hae) {
- LOG.trace("HttpBasicAuthentication failed for " + challenge);
+ if (LOG.isTraceEnabled()) {
+ LOG.trace("HttpBasicAuthentication failed for " + challenge);
+ }
}
authMap.put(realm, newAuth);
return newAuth;
diff --git a/src/plugin/subcollection/src/java/org/apache/nutch/collection/CollectionManager.java b/src/plugin/subcollection/src/java/org/apache/nutch/collection/CollectionManager.java
index 553aff007..3c48fd58d 100644
--- a/src/plugin/subcollection/src/java/org/apache/nutch/collection/CollectionManager.java
+++ b/src/plugin/subcollection/src/java/org/apache/nutch/collection/CollectionManager.java
@@ -63,7 +63,7 @@ public class CollectionManager extends Configured {
protected void init(){
try {
- LOG.info("initializing CollectionManager");
+ if (LOG.isInfoEnabled()) { LOG.info("initializing CollectionManager"); }
// initialize known subcollections
configfile = getConf().getResource(
getConf().get("subcollections.config", DEFAULT_FILE_NAME));
@@ -72,8 +72,10 @@ public class CollectionManager extends Configured {
getConf().get("subcollections.config", DEFAULT_FILE_NAME));
parse(input);
} catch (Exception e) {
- LOG.warn("Error occured:" + e);
- e.printStackTrace(LogUtil.getWarnStream(LOG));
+ if (LOG.isWarnEnabled()) {
+ LOG.warn("Error occured:" + e);
+ e.printStackTrace(LogUtil.getWarnStream(LOG));
+ }
}
}
@@ -84,7 +86,9 @@ public class CollectionManager extends Configured {
NodeList nodeList = collections
.getElementsByTagName(Subcollection.TAG_COLLECTION);
- LOG.info("file has" + nodeList.getLength() + " elements");
+ if (LOG.isInfoEnabled()) {
+ LOG.info("file has" + nodeList.getLength() + " elements");
+ }
for (int i = 0; i < nodeList.getLength(); i++) {
Element scElem = (Element) nodeList.item(i);
@@ -92,7 +96,7 @@ public class CollectionManager extends Configured {
subCol.initialize(scElem);
collectionMap.put(subCol.name, subCol);
}
- } else {
+ } else if (LOG.isInfoEnabled()) {
LOG.info("Cannot find collections");
}
}
@@ -102,7 +106,9 @@ public class CollectionManager extends Configured {
CollectionManager impl = (CollectionManager)conf.getObject(key);
if (impl == null) {
try {
- LOG.info("Instantiating CollectionManager");
+ if (LOG.isInfoEnabled()) {
+ LOG.info("Instantiating CollectionManager");
+ }
impl=new CollectionManager(conf);
conf.setObject(key,impl);
} catch (Exception e) {
@@ -170,7 +176,7 @@ public class CollectionManager extends Configured {
collections += " " + subCol.name;
}
}
- LOG.trace("subcollections:" + collections);
+ if (LOG.isTraceEnabled()) { LOG.trace("subcollections:" + collections); }
return collections;
}
diff --git a/src/plugin/urlfilter-prefix/src/java/org/apache/nutch/urlfilter/prefix/PrefixURLFilter.java b/src/plugin/urlfilter-prefix/src/java/org/apache/nutch/urlfilter/prefix/PrefixURLFilter.java
index 527066056..92e1abbde 100644
--- a/src/plugin/urlfilter-prefix/src/java/org/apache/nutch/urlfilter/prefix/PrefixURLFilter.java
+++ b/src/plugin/urlfilter-prefix/src/java/org/apache/nutch/urlfilter/prefix/PrefixURLFilter.java
@@ -131,11 +131,15 @@ public class PrefixURLFilter implements URLFilter {
if (attributeFile != null && attributeFile.trim().equals(""))
attributeFile = null;
if (attributeFile != null) {
- LOG.info("Attribute \"file\" is defined for plugin " + pluginName
- + " as " + attributeFile);
+ if (LOG.isInfoEnabled()) {
+ LOG.info("Attribute \"file\" is defined for plugin " + pluginName
+ + " as " + attributeFile);
+ }
} else {
- // LOG.warn("Attribute \"file\" is not defined in plugin.xml for
- // plugin "+pluginName);
+ // if (LOG.isWarnEnabled()) {
+ // LOG.warn("Attribute \"file\" is not defined in plugin.xml for
+ // plugin "+pluginName);
+ // }
}
String file = conf.get("urlfilter.prefix.file");
@@ -150,7 +154,7 @@ public class PrefixURLFilter implements URLFilter {
try {
trie = readConfigurationFile(reader);
} catch (IOException e) {
- LOG.fatal(e.getMessage());
+ if (LOG.isFatalEnabled()) { LOG.fatal(e.getMessage()); }
// TODO [email protected]: throw Exception? Because broken api.
throw new RuntimeException(e.getMessage(), e);
}
diff --git a/src/plugin/urlfilter-suffix/src/java/org/apache/nutch/urlfilter/suffix/SuffixURLFilter.java b/src/plugin/urlfilter-suffix/src/java/org/apache/nutch/urlfilter/suffix/SuffixURLFilter.java
index e84fa8c38..e9ab7a2e4 100644
--- a/src/plugin/urlfilter-suffix/src/java/org/apache/nutch/urlfilter/suffix/SuffixURLFilter.java
+++ b/src/plugin/urlfilter-suffix/src/java/org/apache/nutch/urlfilter/suffix/SuffixURLFilter.java
@@ -159,7 +159,9 @@ public class SuffixURLFilter implements URLFilter {
// handle missing config file
if (reader == null) {
- LOG.warn("Missing urlfilter.suffix.file, all URLs will be rejected!");
+ if (LOG.isWarnEnabled()) {
+ LOG.warn("Missing urlfilter.suffix.file, all URLs will be rejected!");
+ }
suffixes = new SuffixStringMatcher(new String[0]);
modeAccept = false;
ignoreCase = false;
@@ -240,10 +242,14 @@ public class SuffixURLFilter implements URLFilter {
}
if (attributeFile != null && attributeFile.trim().equals("")) attributeFile = null;
if (attributeFile != null) {
- LOG.info("Attribute \"file\" is defined for plugin " + pluginName + " as " + attributeFile);
+ if (LOG.isInfoEnabled()) {
+ LOG.info("Attribute \"file\" is defined for plugin " + pluginName + " as " + attributeFile);
+ }
} else {
- // LOG.warn("Attribute \"file\" is not defined in plugin.xml for
- // plugin "+pluginName);
+ // if (LOG.isWarnEnabled()) {
+ // LOG.warn("Attribute \"file\" is not defined in plugin.xml for
+ // plugin "+pluginName);
+ // }
}
String file = conf.get("urlfilter.suffix.file");
@@ -254,7 +260,7 @@ public class SuffixURLFilter implements URLFilter {
try {
readConfigurationFile(reader);
} catch (IOException e) {
- LOG.fatal(e.getMessage());
+ if (LOG.isFatalEnabled()) { LOG.fatal(e.getMessage()); }
throw new RuntimeException(e.getMessage(), e);
}
}