简体   繁体   English

拼凑的LOG_FILE和LOG_LEVEL设置不适用于每个蜘蛛

[英]scrapy LOG_FILE and LOG_LEVEL setting does not work per spider

I have several spiders in my project, and I want to log every spider in independent log file (such as brand.log, product.log ...). 我的项目中有几个蜘蛛,我想将每个蜘蛛记录在独立的日志文件中(例如brand.log,product.log ...)。

So I use the custom_settings per spider, but it doesn't seem to work. 因此,我对每个蜘蛛使用了custom_settings ,但它似乎不起作用。 Is it a bug until now? 到现在为止还是个错误吗? Is there any easy config can solve this problem? 有没有简单的配置可以解决这个问题?

Very thanks for your help! 非常感谢您的帮助!

It's working for me. 它为我工作。 Here is the spider inside a dummy project: 这是一个虚拟项目中的蜘蛛:

# -*- coding: utf-8 -*-
import scrapy

class ExampleSpider(scrapy.Spider):
    name = 'example'
    start_urls = ['http://example.com/']

    custom_settings = {
        'LOG_FILE': '/tmp/example.log',
    }

    def parse(self, response):
        self.logger.info('XXXXX')

I start the spider using scrapy crawl example and the log file is successfully written to /tmp/example.log . 我使用scrapy crawl example启动了Spider,并且日志文件已成功写入/tmp/example.log

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM