mirror of
https://github.com/internetarchive/heritrix3.git
synced 2026-08-27 08:56:46 +00:00
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:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user