Scrapy-日志级别。在AWS Lambda与本地上运行的不同行为

时间:2019-01-21 09:50:43

标签: python logging scrapy aws-lambda

我从脚本https://doc.scrapy.org/en/latest/topics/practices.html#run-scrapy-from-a-script运行Scrapy以从AWS Lambda启动脚本。我用SAM编译了项目,一切都正确了。

但是现在,我遇到了LOG_LEVEL参数的问题。

def handler(event, context):

  settings = {
             'USER_AGENT': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/40.0.2214.85 Safari/537.36',
             'LOG_ENABLED': True,
             'LOG_LEVEL': 'ERROR'
          }

  process = CrawlerProcess(settings=settings)
  process.crawl(Spider)
  process.start()

在本地执行此代码时,一切正确,仅收到LOG_LEVEL:ERROR,但是在AWS Lambda中执行此代码时,我收到LOG_LEVEL:DEBUG,而且我不知道如何解决。

1 个答案:

答案 0 :(得分:1)

根据Scrapy issue #3587中OP的输入,事实证明AWS Lambda在根记录器上安装了自己的处理程序,因此您需要remove those handlers才能使用Scrapy:

from logging import getLogger

getLogger().handlers = []

def handler(event, context):  # AWS Lambda entry point
    pass  # Your code to call Scrapy.