https://github.com/daxartio/kontext
Easy contextual information logging
https://github.com/daxartio/kontext
context-logging contextvars logging python
Last synced: 4 months ago
JSON representation
Easy contextual information logging
- Host: GitHub
- URL: https://github.com/daxartio/kontext
- Owner: daxartio
- License: mit
- Created: 2023-05-03T12:00:59.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2025-08-27T13:29:06.000Z (9 months ago)
- Last Synced: 2025-10-31T00:32:50.685Z (7 months ago)
- Topics: context-logging, contextvars, logging, python
- Language: Python
- Homepage:
- Size: 73.2 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# Python Context Information
[](https://pypi.org/project/kontext/)
[](https://www.python.org/downloads/)
[](https://github.com/daxartio/kontext)
[](https://github.com/daxartio/kontext)
The plugin allows to transfer a context between functions. Inspired by [context-logging](https://github.com/Afonasev/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
```python
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
* [MIT LICENSE](LICENSE)
## Contribution
[Contribution guidelines for this project](CONTRIBUTING.md)