Skip to content

Commit 4bfe575

Browse files
committed
fix(logging): output http response
Signed-off-by: Chris Snow <[email protected]>
1 parent c537236 commit 4bfe575

File tree

2 files changed

+16
-21
lines changed

2 files changed

+16
-21
lines changed

docs/source/cli_overview.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ See https://docs.python.org/3.7/howto/logging.html for much more info on logging
6363
Logging Configuration
6464
---------------------
6565
66-
To change logging configuration, e.g. to log to a file set the environment variable `HPECP_LOG_CONFIG_FILE` and provide a configuration file.
66+
To change logging configuration, e.g. to log to a file, set the environment variable `HPECP_LOG_CONFIG_FILE` and provide a configuration file.
6767
6868
Example: `HPECP_LOG_CONFIG_FILE=~/.hpecp_logging.conf`:
6969

hpecp/client.py

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -658,14 +658,21 @@ def _request(
658658
else:
659659
response_info = ""
660660

661-
if response.status_code == 403:
662-
# This is expected for some method calls so do not log as an
663-
# error
661+
def log_response():
664662
self.log.debug(
665-
"{} : {} {} REQ: {}".format(
666-
description, http_method, url, json.dumps(data)
663+
"RES: {} : {} {} : {} {}".format(
664+
description,
665+
http_method,
666+
url,
667+
response.status_code,
668+
response_info,
667669
)
668670
)
671+
672+
if response.status_code == 403:
673+
# This is expected for some method calls so do not log as an
674+
# error
675+
log_response()
669676
raise APIForbiddenException(
670677
message=response_info,
671678
request_method=http_method,
@@ -675,11 +682,7 @@ def _request(
675682
if response.status_code == 404:
676683
# This is expected for some method calls so do not log as an
677684
# error
678-
self.log.debug(
679-
"{} : {} {} REQ: {}".format(
680-
description, http_method, url, json.dumps(data)
681-
)
682-
)
685+
log_response()
683686
raise APIItemNotFoundException(
684687
message=response_info,
685688
request_method=http_method,
@@ -689,23 +692,15 @@ def _request(
689692
if response.status_code == 409:
690693
# This is expected for some method calls so do not log as an
691694
# error
692-
self.log.debug(
693-
"{} : {} {} REQ: {}".format(
694-
description, http_method, url, json.dumps(data)
695-
)
696-
)
695+
log_response()
697696
raise APIItemConflictException(
698697
message=response_info,
699698
request_method=http_method,
700699
request_url=url,
701700
request_data=json.dumps(data),
702701
)
703702
else:
704-
self.log.debug(
705-
"{} : {} {} REQ: {}".format(
706-
description, http_method, url, json.dumps(data)
707-
)
708-
)
703+
log_response()
709704
raise APIUnknownException(
710705
message=str(re), # get the exception message
711706
request_method=http_method,

0 commit comments

Comments
 (0)