Fixes and improvements to to DecideRuleSequence/logToFile.

* DecideRuleSequence.java
    - use Spring Lifecycle start() to initialize logToFile
    - inject logger module as SimpleFileLoggerProvider, since we're in
      heritrix-modules and don't have access to CrawlerLoggerModule from
      heritrix-engine
* CrawlerLoggerModule.java
    - implement SimpleFileLoggerProvider
    - setupSimpleLog() - use 'T' instead of '+' between date and time in
      timestamp
* SimpleFileLoggerProvider.java
    new interface with one method, setupSimpleLog()
* Scoper.java
    do not call scope.start()/scope.stop(), these are handled using Spring
    Lifecycle now
* DecideRule.java
    remove unused, unneeded start()/stop()
This commit is contained in:
nlevitt
2011-01-07 02:09:31 +00:00
parent bdd7f7e1ab
commit dd439dac3b
5 changed files with 63 additions and 25 deletions
@@ -107,7 +107,6 @@ public abstract class Scoper extends Processor implements Lifecycle {
this.getClass().getName(),
Logger.getLogger(this.getClass().getName()));
}
scope.start();
isRunning = true;
}
@@ -118,7 +117,6 @@ public abstract class Scoper extends Processor implements Lifecycle {
if(fileLogger!=null) {
fileLogger.close();
}
scope.stop();
isRunning = false;
}
@@ -43,6 +43,7 @@ import org.archive.crawler.io.UriErrorFormatter;
import org.archive.crawler.io.UriProcessingFormatter;
import org.archive.crawler.util.Logs;
import org.archive.io.GenerationFileHandler;
import org.archive.modules.SimpleFileLoggerProvider;
import org.archive.modules.extractor.UriErrorLoggerModule;
import org.archive.net.UURI;
import org.archive.spring.ConfigPath;
@@ -60,7 +61,7 @@ import org.springframework.context.Lifecycle;
public class CrawlerLoggerModule
implements
UriErrorLoggerModule, Lifecycle, InitializingBean,
Checkpointable {
Checkpointable, SimpleFileLoggerProvider {
private static final long serialVersionUID = 1L;
protected ConfigPath path = new ConfigPath(Engine.LOGS_DIR_NAME,"logs");
@@ -277,7 +278,7 @@ public class CrawlerLoggerModule
Logger logger = Logger.getLogger(logName + ".log");
Formatter f = new Formatter() {
private SimpleDateFormat dateFmt = new SimpleDateFormat("yyyy-MM-dd+HH:mm:ss.SSS");
private SimpleDateFormat dateFmt = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS");
public String format(java.util.logging.LogRecord record) {
String timestamp = dateFmt.format(new Date(record.getMillis()));
@@ -0,0 +1,25 @@
/*
* This file is part of the Heritrix web crawler (crawler.archive.org).
*
* Licensed to the Internet Archive (IA) by one or more individual
* contributors.
*
* The IA licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.archive.modules;
import java.util.logging.Logger;
public interface SimpleFileLoggerProvider {
public Logger setupSimpleLog(String logName);
}
@@ -76,10 +76,5 @@ public abstract class DecideRule implements Serializable, HasKeyedProperties {
public boolean accepts(CrawlURI uri) {
return DecideResult.ACCEPT == decisionFor(uri);
}
public void start() {
}
public void stop() {
}
}
@@ -23,21 +23,28 @@ import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.archive.crawler.reporting.CrawlerLoggerModule;
import org.archive.modules.CrawlURI;
import org.archive.modules.SimpleFileLoggerProvider;
import org.springframework.beans.factory.BeanNameAware;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.Lifecycle;
public class DecideRuleSequence extends DecideRule implements BeanNameAware{
public class DecideRuleSequence extends DecideRule implements BeanNameAware, Lifecycle {
final private static Logger LOGGER =
Logger.getLogger(DecideRuleSequence.class.getName());
private static final long serialVersionUID = 3L;
protected Logger fileLogger = null;
protected Logger fileLogger = null;
/**
* If enabled, log decisions to file named logs/{spring-bean-id}.log. Format is:
* [timestamp] [decisive-rule-num] [decisive-rule-class] [decision] [uri]
* If enabled, log decisions to file named logs/{spring-bean-id}.log. Format
* is: [timestamp] [decisive-rule-num] [decisive-rule-class] [decision]
* [uri]
*
* Relies on Spring Lifecycle to initialize the log. Only top-level
* beans get the Lifecycle treatment from Spring, so bean must be top-level
* for logToFile to work. (This is true of other modules that support
* logToFile, and anything else that uses Lifecycle, as well.)
*/
{
setLogToFile(false);
@@ -49,12 +56,14 @@ public class DecideRuleSequence extends DecideRule implements BeanNameAware{
kp.put("logToFile",enabled);
}
protected CrawlerLoggerModule loggerModule;
public CrawlerLoggerModule getLoggerModule() {
// provided by CrawlerLoggerModule which is in heritrix-engine, inaccessible
// from here, thus the need for the SimpleFileLoggerProvider interface
protected SimpleFileLoggerProvider loggerModule;
public SimpleFileLoggerProvider getLoggerModule() {
return this.loggerModule;
}
@Autowired
public void setLoggerModule(CrawlerLoggerModule loggerModule) {
public void setLoggerModule(SimpleFileLoggerProvider loggerModule) {
this.loggerModule = loggerModule;
}
@@ -96,12 +105,6 @@ public class DecideRuleSequence extends DecideRule implements BeanNameAware{
return result;
}
public void start() {
if (getLogToFile() && fileLogger == null) {
fileLogger = loggerModule.setupSimpleLog(getBeanName());
}
}
protected String beanName;
public String getBeanName() {
return this.beanName;
@@ -110,5 +113,21 @@ public class DecideRuleSequence extends DecideRule implements BeanNameAware{
public void setBeanName(String name) {
this.beanName = name;
}
protected boolean isRunning = false;
@Override
public boolean isRunning() {
return isRunning;
}
@Override
public void start() {
if (getLogToFile() && fileLogger == null) {
fileLogger = loggerModule.setupSimpleLog(getBeanName());
}
isRunning = true;
}
@Override
public void stop() {
isRunning = false;
}
}