scrapyd&scrapy:如何针对不同spider输出不同日志文件并且能在scrapyd中查看?

  • 回答 (0)
  • 关注 (0)
  • 查看 (41)

我的scrapy项目有多个不同的spider,我想针对不同的spider输出不同的日志文件,所以我在每个spider中重写了`custor_settings`,就像这样

settings = get_project_settings()
today = time.strftime("%Y-%m-%d", time.localtime())
custom_settings = {
    'LOG_ENABLED': True,
    'LOG_FILE': settings.get("LOG_ABS_PATH") + '/logs/Index_' + today + '.log',
    'LOG_FORMAT': settings.get("LOG_FORMAT"),
    'LOG_LEVEL': logging.INFO,
    'LOG_STDOUT': True
}

通过这种方式,我的确能输出日志到不同文件,但是我发现我的 scrapyd 中产生的日志不再能输出所有信息,而是仅仅输出如下一部分信息

2020-04-24 21:02:21 - /home/work/anaconda3/lib/python3.6/site-packages/scrapy/utils/log.py[line:146] - INFO: Scrapy 1.5.0 started (bot: MediaIndex)
2020-04-24 21:02:21 - /home/work/anaconda3/lib/python3.6/site-packages/scrapy/utils/log.py[line:149] - INFO: Versions: lxml 3.7.2.0, libxml2 2.9.3, cssselect 1.0.3, parsel 1.5.1, w3lib 1.20.0, Twisted 17.9.0, Python 3.6.3 |Anaconda custom (64-bit)| (default, Nov  9 2017, 00:19:18) - [GCC 7.2.0], pyOpenSSL 17.2.0 (OpenSSL 1.0.2p  14 Aug 2018), cryptography 2.0.3, Platform Linux-3.18.6-2.el7.centos.x86_64-x86_64-with-centos-7.3.1611-Core
2020-04-24 21:02:21 - /home/work/anaconda3/lib/python3.6/site-packages/scrapy/crawler.py[line:38] - INFO: Overridden settings: {'BOT_NAME': 'MediaIndex', 'CONCURRENT_REQUESTS': 32, 'DOWNLOAD_DELAY': 2, 'LOG_FILE': '/home/work/fuzheng/09.Media_Index/MediaIndex/MediaIndex/logs/TT_Index_2020-04-24.log', 'LOG_FORMAT': '%(asctime)s - %(pathname)s[line:%(lineno)d] - %(levelname)s: %(message)s', 'LOG_LEVEL': 20, 'LOG_STDOUT': True, 'NEWSPIDER_MODULE': 'MediaIndex.spiders', 'SPIDER_MODULES': ['MediaIndex.spiders']}

但是,实际上这里应该输出很多信息才对。我应该如何做才能让scrapyd中的日志这里也输出所有信息呢?

感谢!!!

广埠屯第一暖男广埠屯第一暖男提问于

扫码关注云+社区

领取腾讯云代金券