The logging now using the scrapy setting overrides
This commit is contained in:
parent
2eb8f3e0af
commit
4672903c9b
@ -58,7 +58,7 @@ def search(docopt_arguments, source_loader):
|
||||
:param source_loader: An initiated SourceLoader object pointed at the directory with the sources.
|
||||
"""
|
||||
conf = Configurator()
|
||||
conf.start_log(docopt_arguments["--log"], docopt_arguments["--verbose"])
|
||||
conf.start_log(docopt_arguments["--log"], docopt_arguments["-v"])
|
||||
conf.set_output(docopt_arguments["--output"], docopt_arguments["--format"])
|
||||
setup_crawler(docopt_arguments["<compound>"], conf.scrapy_settings, source_loader, docopt_arguments["--attributes"].split(','))
|
||||
reactor.run()
|
||||
@ -69,8 +69,6 @@ if __name__ == '__main__':
|
||||
arguments = docopt.docopt(__doc__, version='Fourmi - V0.5.0')
|
||||
loader = SourceLoader()
|
||||
|
||||
print arguments["-v"]
|
||||
|
||||
if arguments["--include"]:
|
||||
loader.include(arguments["--include"].split(','))
|
||||
elif arguments["--exclude"]:
|
||||
|
@ -1,6 +1,8 @@
|
||||
import ConfigParser
|
||||
|
||||
from scrapy import log
|
||||
from scrapy.utils.project import get_project_settings
|
||||
import ConfigParser
|
||||
|
||||
|
||||
class Configurator:
|
||||
"""
|
||||
@ -33,20 +35,33 @@ class Configurator:
|
||||
|
||||
def start_log(self, logfile, verbose):
|
||||
"""
|
||||
This function starts the logging functionality of Scrapy using the settings given by the CLI.
|
||||
This function changes the default settings of Scapy's logging functionality
|
||||
using the settings given by the CLI.
|
||||
:param logfile: The location where the logfile will be saved.
|
||||
:param verbose: A boolean value to switch between loglevels.
|
||||
:param verbose: A integer value to switch between loglevels.
|
||||
"""
|
||||
if logfile is not None:
|
||||
if verbose:
|
||||
log.start(logfile=logfile, logstdout=False, loglevel=log.DEBUG)
|
||||
else:
|
||||
log.start(logfile=logfile, logstdout=True, loglevel=log.WARNING)
|
||||
if verbose != 0:
|
||||
self.scrapy_settings.overrides["LOG_ENABLED"] = True
|
||||
else:
|
||||
if verbose:
|
||||
log.start(logstdout=False, loglevel=log.DEBUG)
|
||||
else:
|
||||
log.start(logstdout=True, loglevel=log.WARNING)
|
||||
self.scrapy_settings.overrides["LOG_ENABLED"] = False
|
||||
|
||||
if verbose == 1:
|
||||
self.scrapy_settings.overrides["LOG_LEVEL"] = "WARNING"
|
||||
elif verbose == 2:
|
||||
self.scrapy_settings.overrides["LOG_LEVEL"] = "INFO"
|
||||
else:
|
||||
self.scrapy_settings.overrides["LOG_LEVEL"] = "DEBUG"
|
||||
|
||||
if verbose > 1:
|
||||
self.scrapy_settings.overrides["LOG_STDOUT"] = False
|
||||
else:
|
||||
self.scrapy_settings.overrides["LOG_STDOUT"] = True
|
||||
|
||||
if logfile is not None:
|
||||
self.scrapy_settings.overrides["LOG_FILE"] = logfile
|
||||
else:
|
||||
self.scrapy_settings.overrides["LOG_FILE"] = None
|
||||
|
||||
|
||||
@staticmethod
|
||||
def read_sourceconfiguration():
|
||||
|
Reference in New Issue
Block a user