Skip to main content

Logging utilities for Python applications

Project description

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.

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

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

mtk_logger-0.7.0.tar.gz (6.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mtk_logger-0.7.0-py3-none-any.whl (8.3 kB view details)

Uploaded Python 3

File details

Details for the file mtk_logger-0.7.0.tar.gz.

File metadata

  • Download URL: mtk_logger-0.7.0.tar.gz
  • Upload date:
  • Size: 6.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.25

File hashes

Hashes for mtk_logger-0.7.0.tar.gz
Algorithm Hash digest
SHA256 641f358f42bfc78e23f801a4b519889b203a217a30d1f84fd82cc9d26dc8dde4
MD5 9211ccd043c9c72e432d490442660109
BLAKE2b-256 ab66481cde5893d9c6bde3ddaf03be7668804f6dcd9d7e235da1d12237c0a8c5

See more details on using hashes here.

File details

Details for the file mtk_logger-0.7.0-py3-none-any.whl.

File metadata

  • Download URL: mtk_logger-0.7.0-py3-none-any.whl
  • Upload date:
  • Size: 8.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.25

File hashes

Hashes for mtk_logger-0.7.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0118ee2bcfa032c47d4b4f4ce8cdfde0ebcfc982ff87745409615981721f9104
MD5 8939e349706230d51bebd489787fe2c6
BLAKE2b-256 d0b3c89fe222ef28df3209beebcecd077b061332e890131ff872e887d0cb1cbe

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page