2016-07-12 147 views
3

我想從我的指令碼開始scrapy蜘蛛如圖hereScrapy日誌記錄級別更改

logging.basicConfig(
    filename='log.txt', 
    format='%(levelname)s: %(message)s', 
    level=logging.CRITICAL 
) 
configure_logging(install_root_handler=False) 
process = CrawlerProcess(get_project_settings()) 

process.crawl('1740') 
process.start() # the script will block here until the crawling is finished 

我想配置我的蜘蛛的記錄水平,但即使我不安裝根記錄處理程序和配置我的基本配置logging.basicConfig方法它不服從確定的水平。

INFO: Enabled spider middlewares: 
['scrapy.spidermiddlewares.httperror.HttpErrorMiddleware', 
'scrapy.spidermiddlewares.offsite.OffsiteMiddleware', 
'scrapy.spidermiddlewares.referer.RefererMiddleware', 
'scrapy.spidermiddlewares.urllength.UrlLengthMiddleware', 
'scrapy.spidermiddlewares.depth.DepthMiddleware'] 
INFO: Enabled item pipelines: 
['collector.pipelines.CollectorPipeline'] 
INFO: Spider opened 
INFO: Crawled 0 pages (at 0 pages/min), scraped 0 items (at 0 items/min) 

它是在basicConfig中確定的以下格式和文件名,但它不使用日誌級別。除此之外,我不確定日誌級別。

注意:沒有任何其他地方我導入日誌記錄或更改日誌記錄級別。

回答

1

對於scrapy本身,你應該在settings.pyas described in the docs

定義日誌記錄設置所以在settings.py您可以設置:

LOG_LEVEL = 'ERROR' # to only display errors 
LOG_FORMAT = '%(levelname)s: %(message)s' 
LOG_FILE = 'log.txt' 
+0

是它。第一;即使我改變了它的設置,它只適用於標準輸出日誌。例如,如果我將LOG_ENABLED更改爲False,它不會生成日誌到標準輸出,但它會繼續生成主(上)中確定的文件。這種方法的第二個問題是;這是一個全球性的環境。我想單獨更改記錄器的設置。 – guemues

相關問題