Skip to main content

MTK Logger

Logging utilities for MarkTrack applications.

Installation

To install from GitHub Packages:

# Configure pip to use GitHub Packages
pip config set global.extra-index-url https://YOUR_GITHUB_TOKEN@github.com/pprasquier/mtk_logger/raw/main/dist/

# Install the package
pip install mtk_logger

Or with Poetry:

# Add GitHub Packages as a source
poetry source add --priority=supplemental github https://github.com/pprasquier/mtk_logger/raw/main/dist/

# Install the package
poetry add mtk_logger

Usage

Default import (optional settings_dir; defaults to "settings_files" for backwards compatibility):

from mtk_logger import get_logger

logger = get_logger(__name__)
logger.info("This is a log message")

Custom Prefy settings directory (same pattern as Preferences(settings_dir) elsewhere):

from mtk_logger import get_logger

logger = get_logger(__name__, settings_dir="backend/settings/app")

Structured JSON logs (log_format = json in Prefy) include any keys you set on CorrelationContext, plus fields passed via stdlib extra= (0.7.0+):

from mtk_logger import CorrelationContext, get_logger

logger = get_logger(__name__, settings_dir="path/to/settings")
CorrelationContext.set("cycle_id", "cyc-abc")
CorrelationContext.set("job_id", "job-123")  # vendor-neutral: any string keys
logger.info(
    "doing work",
    extra={"event": "pipeline.cycle.created", "latency_ms": 42},
)

The JSON event field uses extra["event"] when provided; otherwise it falls back to the logger name (0.6.x behaviour). CorrelationContext values override the same key on extra=.

Exports: MTKLogger, get_logger, CorrelationContext, JSONFormatter.

FastAPI middleware

from mtk_logger.fastapi_middleware import RequestLoggingMiddleware

app.add_middleware(RequestLoggingMiddleware)

With a custom settings directory (matches get_logger(..., settings_dir=...)):

from mtk_logger.fastapi_middleware import RequestLoggingMiddleware

app.add_middleware(RequestLoggingMiddleware, settings_dir="backend/settings/app")

RequestLoggingMiddleware sets request_id on CorrelationContext for the request lifetime (restored afterward) and emits latency_ms on the completion log via extra=. Legacy message text is unchanged.

0.9.0 migration note

The public constructor signature and log events are unchanged. Only the implementation moved from Starlette BaseHTTPMiddleware to pure ASGI (async def __call__(self, scope, receive, send)), which avoids deadlocks when stacked with other pure-ASGI middleware under httpx.ASGITransport / TestClient. No application code changes are required beyond bumping the dependency.

See settings_example.json for Prefy keys: log_dir, log_format, process_name, etc.

Metadata

Release files for mtk-logger 0.9.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 mtk-logger 0.9.0
File Size Uploaded Provenance Actions
mtk_logger-0.9.0.tar.gz 7.5 kB Without provenance Details for mtk_logger-0.9.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for mtk-logger 0.9.0
File Interpreter ABI Platform Actions
mtk_logger-0.9.0-py3-none-any.whl Python 3 none any Details for mtk_logger-0.9.0-py3-none-any.whl

Total release size: 16.7 kB

Release files / mtk_logger-0.9.0.tar.gz

Download URL mtk_logger-0.9.0.tar.gz
Size 7.5 kB
Tags Source
SHA-256 checksum
How to use checksums
59914afd00e13edc99c79268777ca51585d9ea49897e1b77d1a40b5212d23ff5
BLAKE2b-256 checksum
How to use checksums
627adfbdfba31f1d4757daaf0d945fb723ad8d944964fffe60bec95ed7777a3a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.25

Release files / mtk_logger-0.9.0-py3-none-any.whl

Download URL mtk_logger-0.9.0-py3-none-any.whl
Size 9.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
83bcc01417fe79397467efee65d999ead2471abb2da18ee6b74ba774f2840700
BLAKE2b-256 checksum
How to use checksums
aa66616a49dec6d9bb3eb3009eb220aa87f94f644862e2e2410e0943110a0d22
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.25

Security for mtk-logger 0.9.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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