Skip to main content

A Python util for automatically adding extra log fields to logs

Project description

py-logging-context

A Python util for automatically adding extra log fields to logs.

Installation

This project is published to PyPI and can be installed using:

pip install py-logging-context==0.1.1

Example Usage

import logging
from py_logging_context import LoggingContext, LoggingContextInjectingFilter

logger = logging.getLogger()
logger.addFilter(LoggingContextInjectingFilter())

with LoggingContext(request_id="some-id", user_name="John Doe"):
    logger.info("Hello world!")  # log record will include `request_id` and `user_name` fields

This library is implemented using Python's Context Variables, and therefore works in multithreaded settings as well asyncio. This is in contrast to solutions based on thread-local data, which will not work as intended async functions (such as log-with-context).

This is a lightweight library and has no additional dependencies.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

py_logging_context-0.1.1.tar.gz (8.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

py_logging_context-0.1.1-py3-none-any.whl (11.0 kB view details)

Uploaded Python 3

File details

Details for the file py_logging_context-0.1.1.tar.gz.

File metadata

  • Download URL: py_logging_context-0.1.1.tar.gz
  • Upload date:
  • Size: 8.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.10.11

File hashes

Hashes for py_logging_context-0.1.1.tar.gz
Algorithm Hash digest
SHA256 d184b0e429ac3fd98cb04dda3f0d5dfb69ac8c408dd5892444ab859338ea2ba1
MD5 95612501a65dcfa1440a06caa10bf42b
BLAKE2b-256 d7d21a1b4500475f7ed47698c2859da3270be3074d72767a04de9f52f827f080

See more details on using hashes here.

File details

Details for the file py_logging_context-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for py_logging_context-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 65a7d2f64ebedd0953cab3bf7d00c0a55dc529112b3fb3b41ae3f56c47ce6c5d
MD5 30acc753799eb3d3ab2ad20247af920e
BLAKE2b-256 94a025c79b382cdb7b5fd1776e6cbad2d7818d79538184e651e1c1c18aa7f129

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page