Skip to content

Releases: u-ways/logging-http-client

2.32.3.9

Choose a tag to compare

@u-ways u-ways released this 17 Dec 09:55

What's Changed

  • feat: Introduce support for response_source attribute by @u-ways in #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.

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: 2.32.3.8...2.32.3.9

2.32.3.8

Choose a tag to compare

@u-ways u-ways released this 15 Dec 13:56

What's Changed

Minor updates after 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: 2.32.3.7...2.32.3.8

2.32.3.7

Choose a tag to compare

@u-ways u-ways released this 15 Dec 13:36

What's Changed

New Contributors

Summary

  • Feat: Support for default logging by @KrinsKumar in #21
  • Docs: Integrate with ReadTheDocs Service by @spyingcyclops in #23
  • Refactor: #12 #14 #24 - Improve The Logging Client Native Requests Feature Support And Enable Multiple Hooks & Obscurers by @u-ways in #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:

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:

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:

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: 2.32.3.6...2.32.3.7

2.32.3.6

Choose a tag to compare

@u-ways u-ways released this 16 Oct 15:17
b54b45f

What's Changed

New Contributors

Full Changelog: 2.32.3.5...2.32.3.6

2.32.3.5

Choose a tag to compare

@u-ways u-ways released this 26 Aug 15:36

What's Changed

  • chore: Update README.md with our versioning strategy details 22a797a
  • feat: Add PyPi badge to reference latest version 9c5c6a2
  • chore: Add monthly downloads badge c86a644

Full Changelog: 2.32.3.4...2.32.3.5

2.32.3.4

Choose a tag to compare

@u-ways u-ways released this 26 Aug 13:37
a5d680e

What's Changed

  • refactor: expose configurations via package entry point to improve usage experience (i.e. avoids extra imports for client config) 6feac54
  • fix: rely on absolute imports to expose package specific imports to users 869e23d

Full Changelog: 2.32.3.3...2.32.3.4

2.32.3.3

Choose a tag to compare

@u-ways u-ways released this 26 Aug 13:32

What's Changed

  • fix: search in the current package before the rest of the PYTHONPATH for package specific imports by @u-ways in #9

Full Changelog: 2.32.3.2...2.32.3.3

2.32.3.2

Choose a tag to compare

@u-ways u-ways released this 23 Aug 20:39

What's Changed

  • feat: add support for Request/Response Log Record obscurers by @u-ways in #6
  • feat: add support for automated x-correlation-id request header setter by @u-ways in #8

Full Changelog: 2.32.3.1...2.32.3.2

2.32.3.1

Choose a tag to compare

@u-ways u-ways released this 20 Aug 14:08
3ef07b2

What's Changed

  • feat: introduce the ability to set custom request and response logging hooks d5a1916
  • feat: introduce the ability to modify the default logging configurations behaviour 1457348

Full Changelog: 2.32.3.0...2.32.3.1

2.32.3.0

Choose a tag to compare

@u-ways u-ways released this 20 Aug 00:23
80d7c93

What's Changed

Details

  • refactor: give production PyPi a more explicit name to reduce the possibility of accidental upload fd93311
  • feat: Introduce manual PyPI deployment pipeline 390fbbb
  • feat: First iteration of the logging HTTP client 1847317
  • feat: First iteration of the logging HTTP client b92c4a7
  • feat: Introduce GH actions CI/CD workflows a5bbd45
  • feat: Introduce the 3 Musketeers pattern via containerised toolchain 8257b02
  • feat: Introduce Poetry with Python 3.12 as the tooling for this project 0205cb5
  • chore: Update .gitignore to ignore user IDE config a7f937b

Full Changelog: https://github.com/u-ways/logging-http-client/commits/2.32.3.0