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 hashes)

Uploaded Source

Supported by

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