There are many configurations on the web that introduce logger, but I found scrapy in the process of execution, and the location of logger.cfg files is also required because scrapy and the common Python script root directory are different
The green font below indicates that the root of scrapy is the direct parent directory with Scrapy.cfg
and the root of the red font is the direct ancestor directory with settings.py,
Here is the difference, to want to general, the simplest way, Just add the Logger.cfg file below the two root directories to
1 logger.cfg
Note/usr/local/log/eie.log and/usr/local/log/ Scrapy.log file has to exist in advance
#logger. CFG [loggers] keys=root,eie,scrapy [handlers] keys=streamhandler,timehandler,scrapyhandler [formatters] Keys =timeformatter,streamformatter [Formatter_streamformatter] format=[% (asctime) s][% (filename) s][line:% (Lineno) d][ % (levelname) s]% (message) s datefmt=%y-%m-%d%h:%m:%s [Formatter_timeformatter] format=[% (asctime) s][% (filename) s][ line:% (Lineno) d][% (levelname) s]% (message) s datefmt=%y-%m-%d%h:%m:%s [logger_root] Level=debug handlers=
Streamhandler,timehandler [Logger_eie] level=debug qualname=eie handlers=timehandler propagate=0 [logger_scrapy] Level=debug qualname=scrapy.utils.log Handlers=scrapyhandler propagate=0 [Handler_streamhandler] class= Streamhandler level=notset formatter=streamformatter args= (Sys.stderr,) [Handler_timehandler] class=handlers. Timedrotatingfilehandler level=debug formatter=streamformatter args= (' F:/pythonwork/eie/log/eie.log ', ' d ', 1, 10) [ Handler_scrapyhandler] Class=handlers. Timedrotatingfilehandler Level=debug Formatter=streamformatter Args= (' F:/pythonwork/eie/log/scrapy.log ', ' d ', 1, 10)
2 udf_config.py
#-*-Coding:utf-8-*-
"Created on
February 14, 2017
Custom configuration Framework
@author: Dzm
'
# log config
import Logging.config
logging.config.fileConfig ('.. /logger.cfg ')
logger = Logging.getlogger (' eie ')
Scrapylogger = Logging.getlogger (' eiescrapy ')
3rd use of the log
Referencing the variable in the Py script is possible.
From eie.middlewares import udf_config
logger = Udf_config.logger