Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] [Feature] Add some basic logging around request/response process. #511

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion shopify/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@
import sys
from six.moves import urllib
import six

import logging
from shopify.collection import PaginatedCollection
from pyactiveresource.collection import Collection
log = logging.getLogger(__name__)

# Store the response from the last request in the connection object

Expand All @@ -23,10 +24,14 @@ def __init__(self, site, user=None, password=None, timeout=None, format=formats.
def _open(self, *args, **kwargs):
self.response = None
try:
log.debug(f"Request: {args, kwargs}")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @samLozier, I think it's better to use different patterns when you do log messages:
log.debug("Request: %s, %s", args, kwargs).
Here is an article on that: https://google.github.io/styleguide/pyguide.html#3101-logging

self.response = super(ShopifyConnection, self)._open(*args, **kwargs)
log.debug(f'Response {self.response}')
except pyactiveresource.connection.ConnectionError as err:
self.response = err.response
log.exception(f"Exception with request: {args, kwargs}, Response: {self.response}")
raise

return self.response


Expand Down
6 changes: 6 additions & 0 deletions shopify/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
from shopify.api_access import ApiAccess
from shopify.api_version import ApiVersion, Release, Unstable
import six
import logging

log = logging.getLogger(__name__)


class ValidationException(Exception):
Expand Down Expand Up @@ -71,10 +74,13 @@ def request_token(self, params):
url = "https://%s/admin/oauth/access_token?" % self.url
query_params = dict(client_id=self.api_key, client_secret=self.secret, code=code)
request = urllib.request.Request(url, urllib.parse.urlencode(query_params).encode("utf-8"))
log.debug(f"Request URL: {url}, query params: {query_params}")
response = urllib.request.urlopen(request)
logging.debug(f"Response: {response}")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you want to use log.debug(...) here instead.


if response.code == 200:
json_payload = json.loads(response.read().decode("utf-8"))
log.debug(f"Response: {json_payload}")
self.token = json_payload["access_token"]
self.access_scopes = json_payload["scope"]

Expand Down