Skip to main content

Easy contextual information logging

Project description

Python Context Information

PyPI PyPI - Python Version GitHub last commit GitHub stars

The plugin allows to transfer a context between functions. Inspired by context-logging.

You can use it for logging data which does not change and can be correlated, e.g. trace_id, correlation_id etc.

Features

  • Thread-safe context management
  • Customizable log records
  • Easy-to-use API

Installation

pip install kontext

Usage

import logging

from kontext import Context, current_context, setup_log_record

logging.basicConfig(format="%(message)s %(kontext)s", level=logging.INFO)
logger = logging.getLogger(__name__)


def bar():
    current_context["foo"] = "bar"
    logger.info("bar")


@Context()
def foo():
    current_context["key"] = "value"
    logger.info("foo")
    bar()


setup_log_record()
foo()
logger.info("Finish")
# foo {'key': 'value'}
# bar {'key': 'value', 'foo': 'bar'}
# Finish {}

For more examples, please refer to the examples directory.

License

Contribution

Contribution guidelines for this project

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

kontext-1.2.1.tar.gz (4.4 kB view hashes)

Uploaded Source

Built Distribution

kontext-1.2.1-py3-none-any.whl (4.8 kB view hashes)

Uploaded Python 3

Supported by

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