From 21b9f377d6d09cfc3bc88d1c09decce9bf75c8ff Mon Sep 17 00:00:00 2001 From: Julia Medina Date: Wed, 4 Mar 2015 15:13:57 -0300 Subject: [PATCH] Deprecate more frequently used functions from scrapy/log.py --- scrapy/log.py | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/scrapy/log.py b/scrapy/log.py index f87bf6461..af0473d46 100644 --- a/scrapy/log.py +++ b/scrapy/log.py @@ -2,9 +2,46 @@ This module is kept to provide a helpful warning about its removal. """ +import logging import warnings + +from twisted.python.failure import Failure + from scrapy.exceptions import ScrapyDeprecationWarning + +logger = logging.getLogger('scrapy') + warnings.warn("Module `scrapy.log` has been deprecated, Scrapy now relies on " "the builtin Python library for logging. Read the updated " "logging entry in the documentation to learn more.", ScrapyDeprecationWarning, stacklevel=2) + + +# Imports kept for backwards-compatibility + +DEBUG = logging.DEBUG +INFO = logging.INFO +WARNING = logging.WARNING +ERROR = logging.ERROR +CRITICAL = logging.CRITICAL +SILENT = CRITICAL + 1 + + +def msg(message, _level=logging.INFO, **kw): + warnings.warn('log.msg has been deprecated, create a python logger and ' + 'log through it instead', + ScrapyDeprecationWarning, stacklevel=2) + + level = kw.pop('level', _level) + logger.log(level, message, kw) + + +def err(_stuff=None, _why=None, **kw): + warnings.warn('log.err has been deprecated, create a python logger and ' + 'use its error method instead', + ScrapyDeprecationWarning, stacklevel=2) + + level = kw.pop('level', logging.ERROR) + failure = kw.pop('failure', _stuff) or Failure() + message = kw.pop('why', _why) or failure.value + logger.log(level, message, kw, extra={'failure': failure})