feat: logging for response status
This commit is contained in:
@@ -14,8 +14,9 @@ from functools import lru_cache as cache # isort:skip
|
|||||||
|
|
||||||
html_forbidden = {html.HtmlComment, }
|
html_forbidden = {html.HtmlComment, }
|
||||||
logging.basicConfig(
|
logging.basicConfig(
|
||||||
level=logging.ERROR,
|
level=logging.INFO,
|
||||||
format='%(asctime)s - %(levelname)s - %(message)s',
|
format="[%(asctime)s] %(levelname)s: %(message)s",
|
||||||
|
datefmt="%Y-%m-%d %H:%M:%S",
|
||||||
handlers=[
|
handlers=[
|
||||||
logging.StreamHandler()
|
logging.StreamHandler()
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -85,7 +85,8 @@ class ResponseEncoding:
|
|||||||
class Response(Adaptor):
|
class Response(Adaptor):
|
||||||
"""This class is returned by all engines as a way to unify response type between different libraries."""
|
"""This class is returned by all engines as a way to unify response type between different libraries."""
|
||||||
|
|
||||||
def __init__(self, url: str, text: str, body: bytes, status: int, reason: str, cookies: Dict, headers: Dict, request_headers: Dict, encoding: str = 'utf-8', **adaptor_arguments: Dict):
|
def __init__(self, url: str, text: str, body: bytes, status: int, reason: str, cookies: Dict, headers: Dict, request_headers: Dict,
|
||||||
|
encoding: str = 'utf-8', method: str = 'GET', **adaptor_arguments: Dict):
|
||||||
automatch_domain = adaptor_arguments.pop('automatch_domain', None)
|
automatch_domain = adaptor_arguments.pop('automatch_domain', None)
|
||||||
self.status = status
|
self.status = status
|
||||||
self.reason = reason
|
self.reason = reason
|
||||||
@@ -96,6 +97,8 @@ class Response(Adaptor):
|
|||||||
super().__init__(text=text, body=body, url=automatch_domain or url, encoding=encoding, **adaptor_arguments)
|
super().__init__(text=text, body=body, url=automatch_domain or url, encoding=encoding, **adaptor_arguments)
|
||||||
# For back-ward compatibility
|
# For back-ward compatibility
|
||||||
self.adaptor = self
|
self.adaptor = self
|
||||||
|
# For easier debugging while working from a Python shell
|
||||||
|
logging.info(f'Fetched ({status}) <{method} {url}> (referer: {request_headers.get("referer")})')
|
||||||
|
|
||||||
# def __repr__(self):
|
# def __repr__(self):
|
||||||
# return f'<{self.__class__.__name__} [{self.status} {self.reason}]>'
|
# return f'<{self.__class__.__name__} [{self.status} {self.reason}]>'
|
||||||
|
|||||||
Reference in New Issue
Block a user