Skip to content

Commit

Permalink
Merge pull request #123 from livechat/Extend_logging
Browse files Browse the repository at this point in the history
Improved logging by appending response headers to the existing log me…
  • Loading branch information
marcindebski authored Dec 15, 2023
2 parents 8a0d966 + e3caadd commit f664c25
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ All notable changes to this project will be documented in this file.

### Changed
- Updated outdated packages.
- Enhanced error logging for improved troubleshooting: Automatically includes response headers in the log for server errors, providing detailed information (such as x-debug-id) for more effective issue diagnosis.

### Bugfixes
- Enabled instantiation for `CustomerRtmV36` within the 3.6 version of the Customer RTM API.
Expand Down
8 changes: 6 additions & 2 deletions livechat/utils/httpx_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ def log_response(self, response: httpx.Response) -> None:
response_content = response.text # to avoid error when response contains binary data
response_debug = f'Response duration: {response.elapsed.total_seconds()} second(s)\n' \
f'Response content:\n{response_content}'

logger.info(f'Response status code: {response.status_code}')
status_code = response.status_code
logger.info(f'Response status code: {status_code}')
if status_code > 499: # log response headers only if status code is 5XX to reduce log bloat
response_headers = json.dumps(dict(response.headers.items()),
indent=4)
response_debug = f'{response_debug}\nResponse headers:\n{response_headers}'
logger.debug(response_debug)
4 changes: 2 additions & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ classifiers =
packages = find:
python_requires = >=3.6
install_requires =
websocket-client==1.6.3
httpx ==0.25.0
websocket-client = >=1.7.0
httpx = >=0.25.0

[options.extras_require]
httpx = http2
Expand Down

0 comments on commit f664c25

Please sign in to comment.