Skip to main content

Uniform JSON logging for University Medicine Essen (UME)

Project description

UME Logging (logging-ume)

PyPI Python Versions License

Uniform JSON logging for University Medicine Essen applications.


Features

  • JSON log output (Docker/K8s/ELK friendly)
  • App/env/service/request context injection
  • PII scrubbing (emails, numeric IDs, phone numbers)
  • OpenTelemetry trace/span IDs in logs
  • Optional log→OTel span event bridge
  • FastAPI middleware for request/response logging
  • Compatible with Python 3.9+

📦 Installation

pip install logging-ume
# Optional extras:
pip install "logging-ume[fastapi]"   # FastAPI request logging middleware
pip install "logging-ume[otel]"      # OpenTelemetry tracing + span events

🚀 Quickstart

import logging
from umelogging import log_configure

log_configure("INFO", app="dicom2fhir", env="prod", service="mapping")
log = logging.getLogger(__name__)

log.info("Starting dicom-to-fhir mapping job.")

Example Output (JSON):

{
  "time": "2025-08-12T12:01:23.456Z",
  "level": "INFO",
  "logger": "myapp",
  "message": "Starting dicom-to-fhir mapping job.",
  "org": "UME",
  "app": "dicom2fhir",
  "env": "prod",
  "service": "mapping"
}

⚙️ Environment Variables

Variable Description Default
UME_LOG_LEVEL Logging level INFO
UME_APP App name
UME_ENV Environment (prod, dev, test) prod
UME_SERVICE Service name
UME_COMPONENT Component/module name
UME_USER_HASH_SALT Salt for user ID hashing ume
UME_OTEL_SPAN_EVENTS Mirror logs as OTel span events false

🌐 FastAPI Integration (optional)

Add request/response logging to your FastAPI app:

from fastapi import FastAPI
from umelogging.fastapi.middleware import UMELoggingMiddleware

app = FastAPI()
app.add_middleware(UMELoggingMiddleware)

This will log incoming requests and responses in JSON, including request ID, latency, status, and correlation information.


📈 OpenTelemetry Integration (optional)

Enable OpenTelemetry tracing and span events in your logs:

from umelogging import log_configure

log_configure(
    "INFO",
    app="myapp",
    env="prod",
    otel_enable=True,  # Enable OpenTelemetry
    otel_exporter="otlp",  # or "console"
)

Configure via environment variables:

Variable Description Example
UMELOG_OTEL_ENABLE Enable OTel tracing/log bridge true
UMELOG_OTEL_EXPORTER OTel exporter ("otlp", "console") otlp
OTEL_EXPORTER_OTLP_ENDPOINT OTel collector endpoint http://otel:4317

See OpenTelemetry Docs for advanced setup.


📄 License

MIT License.
Copyright © University Medicine Essen ZIT / IKIM.

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

ume_logging-0.0.13.tar.gz (7.7 kB view details)

Uploaded Source

Built Distribution

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

ume_logging-0.0.13-py3-none-any.whl (9.4 kB view details)

Uploaded Python 3

File details

Details for the file ume_logging-0.0.13.tar.gz.

File metadata

  • Download URL: ume_logging-0.0.13.tar.gz
  • Upload date:
  • Size: 7.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for ume_logging-0.0.13.tar.gz
Algorithm Hash digest
SHA256 32b8c63d2032bf7f6a83b134a7cd65fc82412cff929db7f46339410723e78430
MD5 8808c8c84cb40c243660e6ec9580b6a8
BLAKE2b-256 d38f57c6ed898c001d6727ba0c424853a557ee9c4da6c13e84c032ca65ee0034

See more details on using hashes here.

Provenance

The following attestation bundles were made for ume_logging-0.0.13.tar.gz:

Publisher: python-publish.yml on UMEssen/ume-logging

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file ume_logging-0.0.13-py3-none-any.whl.

File metadata

  • Download URL: ume_logging-0.0.13-py3-none-any.whl
  • Upload date:
  • Size: 9.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for ume_logging-0.0.13-py3-none-any.whl
Algorithm Hash digest
SHA256 80bca4ff7f40411bc4fc4d4cca7c1abb415c30a007d6a61a9804adcf1a3954fd
MD5 ef86e2dbd0943ae31a76e3d56eb616a6
BLAKE2b-256 13c5a4fb421b02a4b1806417c3aa6adcec5a365eef58301456a930a93f0dfd4c

See more details on using hashes here.

Provenance

The following attestation bundles were made for ume_logging-0.0.13-py3-none-any.whl:

Publisher: python-publish.yml on UMEssen/ume-logging

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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