Easy contextual information logging
Project description
Python Context Information
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
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.3.0.tar.gz
(4.5 kB
view details)
Built Distribution
File details
Details for the file kontext-1.3.0.tar.gz
.
File metadata
- Download URL: kontext-1.3.0.tar.gz
- Upload date:
- Size: 4.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.11.9 Linux/6.5.0-1022-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8241e030664364dcfcde0093c7d6b7bab6355c602031221eec51fe1666fd57dd |
|
MD5 | 54d6f024f57a72e26b136ee365118333 |
|
BLAKE2b-256 | ca70116580c2d3116e681dcdae6a7c49f6283e9f90c18cae7d5d391c9a9b83f7 |
File details
Details for the file kontext-1.3.0-py3-none-any.whl
.
File metadata
- Download URL: kontext-1.3.0-py3-none-any.whl
- Upload date:
- Size: 4.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.11.9 Linux/6.5.0-1022-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3cbea687d230000153bb64a1f11663337a2e529a3b87bdc03443a59ce162060d |
|
MD5 | f9e1825da7b9ed24a59342e773e98f42 |
|
BLAKE2b-256 | 526c8171ad722a324e11b0b0ea89349577f238d1ce560cf3de689f2dd3628276 |