Skip to content

Commit

Permalink
Merge pull request #117 from livechat/Introduce_max_content_length_in…
Browse files Browse the repository at this point in the history
…_logger

Introduced max-content length within the requests param
  • Loading branch information
marcindebski authored Nov 28, 2023
2 parents 51a5c0c + 9ad1368 commit 571120b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
3 changes: 3 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ All notable changes to this project will be documented in this file.

## [0.3.8] - TBA

### Changed
- Implemented truncation of request params in logging for large data.

### Bugfixes
- Allow sending rtm events as a bot by adding `author_id` param.

Expand Down
5 changes: 5 additions & 0 deletions livechat/utils/httpx_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

class HttpxLogger:
''' Logger for httpx requests. '''
MAX_CONTENT_LENGTH_TO_LOG = 1000

def __init__(self, disable_logging: bool = False):
self.disable_logging = disable_logging

Expand All @@ -30,6 +32,9 @@ def log_request(self, request: httpx.Request) -> None:
dict(request.headers.items()),
indent=4,
)
if len(request_params) > self.MAX_CONTENT_LENGTH_TO_LOG:
request_params = f'{request_params[:self.MAX_CONTENT_LENGTH_TO_LOG]}... (Truncated)'

request_debug = f'Request params:\n{request_params}\n' \
f'Request headers:\n{request_headers}'

Expand Down

0 comments on commit 571120b

Please sign in to comment.