Chapter 1.6 Scrapy of the Logger

Source: Internet
Author: User
Tags parent directory python script

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.