Skip to main content

A middleware to log all requests in FastAPI

Project description

FastAPI Route Logger

Usage

from typing import Union

from fastapi import FastAPI

from route_logger_middleware import GlobalLoggerMiddleware
from route_logger_middleware.backends.mqtt_backend import MQTTBackend

app = FastAPI()

backend = MQTTBackend(hostname="localhost", topic="logs")
app.add_middleware(GlobalLoggerMiddleware, backend=backend, module_name="my-awesome-app")


@app.get("/")
def read_root():
    return {"Hello": "World"}


@app.get("/items/{item_id}")
def read_item(item_id: int, q: Union[str, None] = None):
    return {"item_id": item_id, "q": q}

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

route-logger-fastapi-middleware-0.0.1.tar.gz (3.4 kB view details)

Uploaded Source

File details

Details for the file route-logger-fastapi-middleware-0.0.1.tar.gz.

File metadata

File hashes

Hashes for route-logger-fastapi-middleware-0.0.1.tar.gz
Algorithm Hash digest
SHA256 f6ab405859d2fbfa246a94970526d7bfd24ef18a37717aa4bac06489d88fed7d
MD5 bf8d55187fa84261f6a7f227eb56add9
BLAKE2b-256 bb9fcfb5f3ac0038666d8ce7e653e82e71b2d48ca30aaf7cbe204f8d96d7e48d

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