From 9f0001af26a8a2d214be34c724132744eea8b60a Mon Sep 17 00:00:00 2001 From: Karim shoair Date: Wed, 11 Dec 2024 20:14:32 +0200 Subject: [PATCH] feat: logging for response status --- scrapling/core/utils.py | 5 +++-- scrapling/engines/toolbelt/custom.py | 5 ++++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/scrapling/core/utils.py b/scrapling/core/utils.py index 35f8d0a..a911757 100644 --- a/scrapling/core/utils.py +++ b/scrapling/core/utils.py @@ -14,8 +14,9 @@ from functools import lru_cache as cache # isort:skip html_forbidden = {html.HtmlComment, } logging.basicConfig( - level=logging.ERROR, - format='%(asctime)s - %(levelname)s - %(message)s', + level=logging.INFO, + format="[%(asctime)s] %(levelname)s: %(message)s", + datefmt="%Y-%m-%d %H:%M:%S", handlers=[ logging.StreamHandler() ] diff --git a/scrapling/engines/toolbelt/custom.py b/scrapling/engines/toolbelt/custom.py index eabd219..7c8acd6 100644 --- a/scrapling/engines/toolbelt/custom.py +++ b/scrapling/engines/toolbelt/custom.py @@ -85,7 +85,8 @@ class ResponseEncoding: class Response(Adaptor): """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) self.status = status 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) # For back-ward compatibility 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): # return f'<{self.__class__.__name__} [{self.status} {self.reason}]>'