You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

60 lines
2.0 KiB

4 years ago
  1. """
  2. This module is kept to provide a helpful warning about its removal.
  3. """
  4. import logging
  5. import warnings
  6. from twisted.python.failure import Failure
  7. from scrapy.exceptions import ScrapyDeprecationWarning
  8. from scrapy.utils.log import failure_to_exc_info
  9. logger = logging.getLogger(__name__)
  10. warnings.warn("Module `scrapy.log` has been deprecated, Scrapy now relies on "
  11. "the builtin Python library for logging. Read the updated "
  12. "logging entry in the documentation to learn more.",
  13. ScrapyDeprecationWarning, stacklevel=2)
  14. # Imports and level_names variable kept for backwards-compatibility
  15. DEBUG = logging.DEBUG
  16. INFO = logging.INFO
  17. WARNING = logging.WARNING
  18. ERROR = logging.ERROR
  19. CRITICAL = logging.CRITICAL
  20. SILENT = CRITICAL + 1
  21. level_names = {
  22. logging.DEBUG: "DEBUG",
  23. logging.INFO: "INFO",
  24. logging.WARNING: "WARNING",
  25. logging.ERROR: "ERROR",
  26. logging.CRITICAL: "CRITICAL",
  27. SILENT: "SILENT",
  28. }
  29. def msg(message=None, _level=logging.INFO, **kw):
  30. warnings.warn('log.msg has been deprecated, create a python logger and '
  31. 'log through it instead',
  32. ScrapyDeprecationWarning, stacklevel=2)
  33. level = kw.pop('level', _level)
  34. message = kw.pop('format', message)
  35. # NOTE: logger.log doesn't handle well passing empty dictionaries with format
  36. # arguments because of some weird use-case:
  37. # https://hg.python.org/cpython/file/648dcafa7e5f/Lib/logging/__init__.py#l269
  38. logger.log(level, message, *[kw] if kw else [])
  39. def err(_stuff=None, _why=None, **kw):
  40. warnings.warn('log.err has been deprecated, create a python logger and '
  41. 'use its error method instead',
  42. ScrapyDeprecationWarning, stacklevel=2)
  43. level = kw.pop('level', logging.ERROR)
  44. failure = kw.pop('failure', _stuff) or Failure()
  45. message = kw.pop('why', _why) or failure.value
  46. logger.log(level, message, *[kw] if kw else [], exc_info=failure_to_exc_info(failure))