A Python implementation of Mapped Diagnostic Context (MDC) for structured logging. MDC allows you to enrich log records with contextual key-value pairs, propagate context across threads and async code, and format logs as JSON. Current version 1.2.1, released on PyPI, with irregular releases.
pip install mdcVerified import paths — ran on the pinned version, not inferred.
Basic usage: use MDC as a context manager to add key-value pairs to log records.
Upgrade to >=1.2.0 and review your usage of MDC as a decorator or context manager.
When spawning threads or tasks, manually copy the MDC context: context = MDC.get_context(); # pass to thread/task
Use from mdc import MDC, MDCFormatter and configure logging with MDCFormatter on any Handler.
Upgrade to 1.2.1 or later to preserve context throughout generator execution.
Install the latest version: pip install --upgrade mdc
Convert values to strings before passing to MDC: MDC(user_id=str(1234))
Run pip install --upgrade mdc. If problem persists, check your environment for conflicting mdc installations.
No dependency data recorded yet.