Logging-http-client

Latest version: v2.32.3.9

Safety actively analyzes 706267 Python packages for vulnerabilities to keep your Python projects secure.

Scan your dependencies

Page 1 of 2

2.32.3.9

What's Changed

* feat: Introduce support for `response_source` attribute by u-ways in https://github.com/u-ways/logging-http-client/pull/27

Details

The HTTP log record will now include a new attribute, `response_source`. It will try to collect it from the `X_SOURCE_HEADER` if that cannot be found, it will rely on the `request.url` host (and port) values.

python
record.response_source = response.headers.get(X_SOURCE_HEADER, None)

if record.response_source is None:
try:
record.response_source = urlparse(response.request.url).netloc
except ValueError:
record.response_source = "UNKNOWN"


**Full Changelog**: https://github.com/u-ways/logging-http-client/compare/2.32.3.8...2.32.3.9

2.32.3.8

What's Changed

Minor updates after [releases/tag/2.32.3.7](https://github.com/u-ways/logging-http-client/releases/tag/2.32.3.7) release.

Summary

- fix: correct `http_headers` import path as we rely on relative importing
- doc: abbreviate subsection 5.3 title
- doc: add missing subsection in table of contents

**Full Changelog**: https://github.com/u-ways/logging-http-client/compare/2.32.3.7...2.32.3.8

2.32.3.7

What's Changed

New Contributors
* KrinsKumar made their first contribution in https://github.com/u-ways/logging-http-client/pull/21
* spyingcyclops made their first contribution in https://github.com/u-ways/logging-http-client/pull/22


Summary
* Feat: Support for default logging by KrinsKumar in https://github.com/u-ways/logging-http-client/pull/21
* Docs: Integrate with ReadTheDocs Service by spyingcyclops in https://github.com/u-ways/logging-http-client/pull/23
* Refactor: 12 14 24 - Improve The Logging Client Native Requests Feature Support And Enable Multiple Hooks & Obscurers by u-ways in https://github.com/u-ways/logging-http-client/pull/25

Details

1. Read The Docs Endpoint

This is one of the bigger releases for this library, for starters, we now have ReadTheDocs endpoint for those who prefer reading the documentation there: https://logging-http-client.readthedocs.io/en/latest/

2. Ability to Customize The Default Hook Log Level

On top of that, we now support customizing the default logging hooks log level, by default, they will log at the `INFO` level, but from now on, you can specify the desired level as an integer per Python log level setting conventions:

python
import logging

import logging_http_client

"""
CRITICAL = 50
ERROR = 40
WARNING = 30
INFO = 20
DEBUG = 10
NOTSET = 0
"""
logging_http_client.set_default_hooks_logging_level(logging.DEBUG)

logging_http_client.create().get('https://www.python.org')
=> Logs will be recorded at the DEBUG level now.


3. Support For Accumulative Obscurers And Multiple Logging Hooks

Previously, you could only provide a single logging hook for requests or response logging. From now on, the configurations allows you to provide multiple obscurers and multiple looks:

python
import logging

from requests import Response

import logging_http_client


def custom_response_logging_hook(logger: logging.Logger, response: Response):
logger.debug("Custom response logging for %s", response.url)


def custom_response_logging_hook_2(logger: logging.Logger, response: Response):
logger.debug("Another custom response logging for %s", response.url)


logging_http_client.set_response_logging_hooks(
[custom_response_logging_hook, custom_response_logging_hook_2]
)

logging_http_client.create().get('https://www.python.org')

=> Log records will include:
{ message { "Custom response logging for https://www.python.org" } }
{ message { "Another custom response logging for https://www.python.org" } }


Here is how you can also utilize both in your application:

python
import logging
import logging_http_client

from requests import PreparedRequest
from logging_http_client import HttpLogRecord


def custom_request_logging_hook(logger: logging.Logger, request: PreparedRequest):
logger.debug(
"Custom request logging for %s",
request.url,
IMPORTANT: Usage of this static method will automatically apply the obscurers for you.
extra=HttpLogRecord.from_request(request)
)


def first_request_obscurer(record: HttpLogRecord) -> HttpLogRecord:
if record.request_headers.get("Authorization"):
record.request_headers["Authorization"] = "Bearer ****"
return record


def second_request_obscurer(record: HttpLogRecord) -> HttpLogRecord:
if record.request_body:
record.request_body = "OBSCURED_BODY"
return record


logging_http_client.enable_request_body_logging()
logging_http_client.set_request_logging_hooks([custom_request_logging_hook])
logging_http_client.set_request_log_record_obscurers([first_request_obscurer, second_request_obscurer])

root_logger = logging.getLogger()
root_logger.setLevel(level=logging.DEBUG)

client = logging_http_client.create(logger=root_logger)
client.post(
url="https://www.python.org",
headers={"accept": "application/json", "Authorization": "Bearer secret"},
json={"sensitive": "data"},
)
=> Log record will include:
{ http { 'request_headers': { 'Authorization': 'Bearer ****', ... }, 'request_body': 'OBSCURED_BODY', ... }
`

The older methods are still there for backwards compatibility but they're marked as deprecated and will be removed in a future (next) `logging-http-client` version.

For further details, read: https://github.com/u-ways/logging-http-client?tab=readme-ov-file#iii-activating-the-log-record-obscurer-in-your-own-custom-logging-hooks

4. The Logging Session Implementation Details Has Been Greatly Improved.

Finally, the logging session implementation was a bit rough, didn't factor in prepared statements (prepared requests), and was unnecessarily complex. I have revised the logic over this weekend and now it's much easier to understand and maintain for future contributors. 🙂

**Full Changelog**: https://github.com/u-ways/logging-http-client/compare/2.32.3.6...2.32.3.7

2.32.3.6

What's Changed
* feat: add CONTRIBUTING.md file by u-ways in https://github.com/u-ways/logging-http-client/pull/17
* fix: pass valid kwargs to Request object inside decorate - Issue 18 by skywaltonr in https://github.com/u-ways/logging-http-client/pull/19
* chore: increment version to "2.32.3.6" by skywaltonr in https://github.com/u-ways/logging-http-client/pull/20

New Contributors
* skywaltonr made their first contribution in https://github.com/u-ways/logging-http-client/pull/19

**Full Changelog**: https://github.com/u-ways/logging-http-client/compare/2.32.3.5...2.32.3.6

2.32.3.5

What's Changed

- chore: Update README.md with our versioning strategy details 22a797a6
- feat: Add PyPi badge to reference latest version 9c5c6a21
- chore: Add monthly downloads badge c86a6441

**Full Changelog**: https://github.com/u-ways/logging-http-client/compare/2.32.3.4...2.32.3.5

2.32.3.4

What's Changed
* refactor: expose configurations via package entry point to improve usage experience (i.e. avoids extra imports for client config) 6feac54d
* fix: rely on absolute imports to expose package specific imports to users 869e23d9

**Full Changelog**: https://github.com/u-ways/logging-http-client/compare/2.32.3.3...2.32.3.4

Page 1 of 2

© 2025 Safety CLI Cybersecurity Inc. All Rights Reserved.