Scrapy use of log logging
1, meaning:
To facilitate debugging. In scrapy operation may not stop, there is no record close. Therefore, the log is saved in text easy to see the information.
2, the use of:
1) an increase in the settings:
# log config
import datetime
Today=datetime.datetime.now()#取得现在的时间
Log_file_path='scrapy_{}_{}_{}.log'.format(Today.year,Today.month,Today.day)#以时间为文件名
LOG_LEVEL="WARNING"#级别,则高于或者等于该等级的信息就能输出到我的日志中,低于该级别的信息则输出不到我的日志信息中
#logging.warning
LOG_FILE =Log_file_path
#Log_file_path='log/scrapy_{}_{}_{}.log'.format(Today.year,Today.month,Today.day) 则在目标下增加log文件夹
Scrapy offer 5 layer logging level:
CRITICAL - Critical error
ERROR - General error
WARNING - warning messages
INFO - General Information
DEBUG - Debug Information
logging settings
may be used by the logging in setting.py the following settings:
LOG_ENABLED default: True, Enable logging
LOG_ENCODING Default: 'utf-8', encoded using logging
LOG_FILE Default: None, create logging output file in the current directory in the file name
LOG_LEVEL default: 'DEBUG', log the lowest level
2) specific use:
import logging
logging.warning (“日志信息”)