Skip to main content

contextfilter

Version License Tests

Small, helper library for logging contextual information using contextvars in Python 3.7.

Installation

Using pip

$ pip install contextfilter

Usage

import logging
from contextvars import ContextVar
from contextfilter import ContextVarFilter, ConstContextFilter

request_id: ContextVar[int] = ContextVar('request_id')
logger = logging.getLogger("test")
cf = ContextFilter(request_id=request_id)
request_id.set(3)
logger.addFilter(cf)
logger.info("test")
# Log record will contain the attribute request_id with value 3

cf = ConstContextFilter(some_const=1)
logger.addFilter(cf)
logger.info("test")
# Log record will contain the attribute some_const with value 1.

Contributing

To work on the contextfilter codebase, you'll want to fork the project and clone it locally and install the required dependencies via poetry:

$ git clone git@github.com:{USER}/contextfilter.git
$ make install

To run tests and linters use command below:

$ make lint && make test

If you want to run only tests or linters you can explicitly specify which test environment you want to run, e.g.:

$ make lint-black

License

contextfilter is licensed under the MIT license. See the license file for details.

Latest changes

0.3.0 (2020-8-14)

  • Renamed ContextFilter to ContextVarFilter - Revamped the API - It now accepts ContextVars created by caller. Suggestion for design by @bentheiii
  • Added ConstContextFilter which adds constant attributes to the log record.
  • Fixed #5

Release files for contextfilter 0.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for contextfilter 0.3.0
File Size Uploaded
contextfilter-0.3.0.tar.gz 3.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for contextfilter 0.3.0
File Interpreter ABI Platform
contextfilter-0.3.0-py3-none-any.whl Python 3 none any Details

Total release size: 7.2 kB

Release files / contextfilter-0.3.0.tar.gz

Download URL contextfilter-0.3.0.tar.gz
Size 3.5 kB
Tags Source
SHA-256 checksum
How to use checksums
8c0fb54ffb1eb5537979244a0a273ec9a870c326d674d7ad56237de400ac3f70
BLAKE2b-256 checksum
How to use checksums
47f266d89ef3de063cd80e497b975b26dd0aeff6ca9d9739c0a5720dfd2f3664
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.0.10 CPython/3.7.8 Linux/5.3.0-1034-azure

Release files / contextfilter-0.3.0-py3-none-any.whl

Download URL contextfilter-0.3.0-py3-none-any.whl
Size 3.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7c68c4cf58a62230e27c13ab2717b2d7e93508934b62dce59661dbaada8261ec
BLAKE2b-256 checksum
How to use checksums
5d81f95580d147c9aa87228b3535f6a6f6f28f39c55560ba51ebc7f76d54604f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.0.10 CPython/3.7.8 Linux/5.3.0-1034-azure

Release history Release notifications | RSS feed

This release

0.3.0 This release

2 release files

0.2.0

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page