Skip to content
This repository has been archived by the owner on Apr 23, 2024. It is now read-only.

Commit

Permalink
switch from general requests logging to custom http logging events (#169
Browse files Browse the repository at this point in the history
)

* switch from general requests logging to custom http logging events

* optimize logging

* remove basicConfig
  • Loading branch information
SebRut committed Jul 28, 2021
1 parent 210c26c commit db28fd7
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions pygrocy/grocy_api_client.py
Expand Up @@ -542,16 +542,6 @@ def __init__(self, parsed_json):
def _enable_debug_mode():
_LOGGER.setLevel(logging.DEBUG)

# log http request related data
from http.client import HTTPConnection

HTTPConnection.debuglevel = 1
logging.basicConfig()
logging.getLogger().setLevel(logging.DEBUG)
requests_log = logging.getLogger("urllib3")
requests_log.setLevel(logging.DEBUG)
requests_log.propagate = True


class GrocyApiClient(object):
def __init__(
Expand Down Expand Up @@ -579,7 +569,9 @@ def _do_get_request(self, end_url: str):
req_url = urljoin(self._base_url, end_url)
resp = requests.get(req_url, verify=self._verify_ssl, headers=self._headers)

_LOGGER.debug(f"response: {resp.content}")
_LOGGER.debug("-->\tGET /%s", end_url)
_LOGGER.debug("<--\t%d for /%s", resp.status_code, end_url)
_LOGGER.debug("\t\t%s", resp.content)

if resp.status_code >= 400:
raise GrocyError(resp)
Expand All @@ -593,7 +585,10 @@ def _do_post_request(self, end_url: str, data: dict):
req_url, verify=self._verify_ssl, headers=self._headers, json=data
)

_LOGGER.debug(f"response: {resp.content}")
_LOGGER.debug("-->\tPOST /%s", end_url)
_LOGGER.debug("\t\t%s", data)
_LOGGER.debug("<--\t%d for /%s", resp.status_code, end_url)
_LOGGER.debug("\t\t%s", resp.content)

if resp.status_code >= 400:
raise GrocyError(resp)
Expand All @@ -613,7 +608,10 @@ def _do_put_request(self, end_url: str, data):
req_url, verify=self._verify_ssl, headers=up_header, data=data
)

_LOGGER.debug(f"response: {resp.content}")
_LOGGER.debug("-->\tPUT /%s", end_url)
_LOGGER.debug("\t\t%s", data)
_LOGGER.debug("<--\t%d for /%s", resp.status_code, end_url)
_LOGGER.debug("\t\t%s", resp.content)

if resp.status_code >= 400:
raise GrocyError(resp)
Expand All @@ -625,7 +623,9 @@ def _do_delete_request(self, end_url: str):
req_url = urljoin(self._base_url, end_url)
resp = requests.get(req_url, verify=self._verify_ssl, headers=self._headers)

_LOGGER.debug(f"response: {resp.content}")
_LOGGER.debug("-->\tDELETE /%s", end_url)
_LOGGER.debug("<--\t%d for /%s", resp.status_code, end_url)
_LOGGER.debug("\t\t%s", resp.content)

if resp.status_code >= 400:
raise GrocyError(resp)
Expand Down

0 comments on commit db28fd7

Please sign in to comment.