我使用scrapy 1.1.0,并且我在“蜘蛛”文件夹中有5个蜘蛛。scrapy使用python3日志记录模块问题
在每个蜘蛛中,我尝试使用python3日志模块。和代码结构是这样的:
import other modules
import logging
class ExampleSpider(scrapy.Spider):
name = 'special'
def __init__(self):
# other initializations
# set log
self.log = logging.getLogger('special')
self.log.setLevel(logging.DEBUG)
logFormatter = logging.Formatter('%(asctime)s %(levelname)s: %(message)s')
# file handler
fileHandler = logging.FileHandler(LOG_PATH) # LOG_PATH has defined
fileHandler.setLevel(logging.DEBUG)
fileHandler.setFormatter(logFormater)
self.log.addHandler(fileHandler)
# other functions
每个蜘蛛我运行这些蜘蛛一样structure.When,我检查日志文件,他们确实存在,但它们的大小始终为0字节。
而另一个问题是,当我运行一个蜘蛛时,它总是生成两个或更多的日志文件。像我运行a
蜘蛛,它会生成a.log
和b.log
。
任何答案将不胜感激。
你用'self.log'登录什么?即'self.log.warning('something')'? scrapy有它自己的记录器,其他所有组件也是如此,你在这里做的是只为你的记录器设置文件处理程序等。 – Granitosaurus
@Granitosaurus我只想将scrapy输出保存为一个日志文件,我知道现在scrapy(版本1.1.0)已经被弃用,并且支持显式调用Python标准日志记录。 –