在settings中设置
LOG_LEVEL = 'WARNING'
LOG_FILE = '/data/log.log'
Scrapy提供5层logging级别:
- CRITICAL - 严重错误(critical)
- ERROR - 一般错误(regular errors)
- WARNING - 警告信息(warning messages)
- INFO - 一般信息(informational messages)
- DEBUG - 调试信息(debugging messages)
调用方法如下,在pipelines.py中:
import logging
logger = logging.getLogger(__name__)
def process_item(self, item, spider):
logger.warning(item)
....