mirror of https://github.com/scrapy/scrapy.git
Merge bfc219d5b7 into d8ba1571e7
This commit is contained in:
commit
abe33c7305
|
|
@ -208,12 +208,6 @@ scrapy.Spider
|
|||
:param response: the response to parse
|
||||
:type response: :class:`~scrapy.http.Response`
|
||||
|
||||
.. method:: log(message, [level])
|
||||
|
||||
Wrapper that sends a log message through the Spider's :attr:`logger`,
|
||||
kept for backward compatibility. For more information see
|
||||
:ref:`topics-logging-from-spiders`.
|
||||
|
||||
.. method:: closed(reason)
|
||||
|
||||
Called when the spider closes. This method provides a shortcut to
|
||||
|
|
|
|||
|
|
@ -7,9 +7,11 @@ See documentation in docs/topics/spiders.rst
|
|||
from __future__ import annotations
|
||||
|
||||
import logging
|
||||
import warnings
|
||||
from typing import TYPE_CHECKING, Any, cast
|
||||
|
||||
from scrapy import signals
|
||||
from scrapy.exceptions import ScrapyDeprecationWarning
|
||||
from scrapy.http import Request, Response
|
||||
from scrapy.utils.trackref import object_ref
|
||||
from scrapy.utils.url import url_is_from_spider
|
||||
|
|
@ -66,6 +68,11 @@ class Spider(object_ref):
|
|||
can use it directly (e.g. Spider.logger.info('msg')) or use any other
|
||||
Python logger too.
|
||||
"""
|
||||
warnings.warn(
|
||||
"Spider.log() is deprecated, use methods of Spider.logger instead.",
|
||||
ScrapyDeprecationWarning,
|
||||
stacklevel=2,
|
||||
)
|
||||
self.logger.log(level, message, **kw)
|
||||
|
||||
@classmethod
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ from testfixtures import LogCapture
|
|||
|
||||
from scrapy import signals
|
||||
from scrapy.crawler import Crawler
|
||||
from scrapy.exceptions import ScrapyDeprecationWarning
|
||||
from scrapy.http import Response, TextResponse, XmlResponse
|
||||
from scrapy.settings import Settings
|
||||
from scrapy.spiders import CSVFeedSpider, Spider, XMLFeedSpider
|
||||
|
|
@ -116,7 +117,12 @@ class TestSpider:
|
|||
|
||||
def test_log(self):
|
||||
spider = self.spider_class("example.com")
|
||||
with mock.patch("scrapy.spiders.Spider.logger") as mock_logger:
|
||||
with (
|
||||
mock.patch("scrapy.spiders.Spider.logger") as mock_logger,
|
||||
pytest.warns(
|
||||
ScrapyDeprecationWarning, match=r"Spider.log\(\) is deprecated"
|
||||
),
|
||||
):
|
||||
spider.log("test log msg", "INFO")
|
||||
mock_logger.log.assert_called_once_with("INFO", "test log msg")
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue