From 7e8ccb6c77c55d4c89f9c77f8deead262e891cf5 Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 22 Dec 2024 11:13:03 +0000 Subject: [PATCH] add debug logging --- sp_api/base/client.py | 42 ++++++++++++++---------------------------- 1 file changed, 14 insertions(+), 28 deletions(-) diff --git a/sp_api/base/client.py b/sp_api/base/client.py index a842c4e8..f4f17fc6 100644 --- a/sp_api/base/client.py +++ b/sp_api/base/client.py @@ -15,32 +15,9 @@ from sp_api.base.credential_provider import CredentialProvider log = logging.getLogger(__name__) +log.setLevel(logging.INFO) # Set default to DEBUG; users can override externally -def show_donation_message(): - import os - - if os.environ.get("ENV_DISABLE_DONATION_MSG", 0) == "1": - return - - print("🌟 Thank you for using python-amazon-sp-api! 🌟") - print( - "This tool helps developers and businesses connect seamlessly with Amazon's vast marketplace," - ) - print("enabling powerful automations and data management.") - print( - "If you appreciate this project and find it useful, please consider supporting its continued development:" - ) - print(" - 🙌 GitHub Sponsors: https://github.com/sponsors/saleweaver") - print(" - 🌐 BTC Address: bc1q6uqgczasmnvnc5upumarugw2mksnwneg0f65ws") - print(" - 🌐 ETH Address: 0xf59534F7a7F5410DBCD0c779Ac3bB6503bd32Ae5") - print( - "\nYour support helps keep the project alive and evolving, and is greatly appreciated!" - ) - print( - "\nTo disable this donation message, set the ENV_DISABLE_DONATION_MSG=1 environment variable." - ) - class Client(BaseClient): grantless_scope: str = "" @@ -86,7 +63,6 @@ def __init__( self.timeout = timeout self.version = version self.verify = verify - show_donation_message() @property def headers(self): @@ -134,6 +110,12 @@ def _request( if add_marketplace: self._add_marketplaces(data if self.method in ("POST", "PUT") else params) + log.debug("HTTP Method: %s", self.method) + log.debug("Making request to URL: %s", self.endpoint + self._check_version(path)) + log.debug("Request Params: %s", params) + log.debug("Request Data: %s", data if self.method in ("POST", "PUT", "PATCH") else None) + log.debug("Request Headers: %s", headers or self.headers) + res = request( self.method, self.endpoint + self._check_version(path), @@ -178,11 +160,11 @@ def _check_response( error = js.get("errors", None) if error: + log.debug("Error Response: %s", error) exception = get_exception_for_code(res.status_code) raise exception(error, headers=res.headers) - # show_donation_message() - + log.debug("Response: %s", js) return ApiResponse(**js, headers=res.headers) def _add_marketplaces(self, data): @@ -221,7 +203,11 @@ def _request_grantless_operation( "x-amz-date": datetime.utcnow().strftime("%Y%m%dT%H%M%SZ"), "content-type": "application/json", } - + log.debug("HTTP Method: %s", self.method) + log.debug("Making request to URL: %s", self.endpoint + self._check_version(path)) + log.debug("Request Params: %s", params) + log.debug("Request Data: %s", data if self.method in ("POST", "PUT", "PATCH") else None) + log.debug("Request Headers: %s", headers or self.headers) return self._request(path, data=data, params=params, headers=headers) def _check_version(self, path):