Logging middleware for Swarmauri
Project description
Swarmauri Middleware Logging
HTTP middleware for logging requests and responses in Swarmauri and FastAPI applications.
Features
- Logs the HTTP method and path for each incoming request.
- Captures request headers and attempts to parse JSON bodies for inspection.
- Emits a warning when the request body cannot be decoded as JSON.
- Measures total processing time and records the response status code.
Installation
Install the package with your preferred Python packaging tool:
pip install swarmauri_middleware_logging
poetry add swarmauri_middleware_logging
uv pip install swarmauri_middleware_logging
uv add swarmauri_middleware_logging
Example
from fastapi import FastAPI, Request
from fastapi.testclient import TestClient
from swarmauri_middleware_logging import LoggingMiddleware
app = FastAPI()
logging_middleware = LoggingMiddleware()
@app.middleware("http")
async def log_requests(request: Request, call_next):
return await logging_middleware.dispatch(request, call_next)
@app.post("/echo")
async def echo(payload: dict):
return payload
client = TestClient(app)
print(client.post("/echo", json={"message": "hello"}).json())
Running the example prints the echoed payload and produces INFO-level log entries for the request and response lifecycle.
Want to help?
If you want to contribute to swarmauri-sdk, read up on our guidelines for contributing that will help you get started.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file swarmauri_middleware_logging-0.8.0.dev46.tar.gz.
File metadata
- Download URL: swarmauri_middleware_logging-0.8.0.dev46.tar.gz
- Upload date:
- Size: 7.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.10.12 {"installer":{"name":"uv","version":"0.10.12","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
acdc8f0ef0199e02fce70553e8b9d62a2f6a9b1821be8c4ca50aca17aedd9f9b
|
|
| MD5 |
89dd9c35f73398d47bd52c9be42f3851
|
|
| BLAKE2b-256 |
2481db5709b6c383ecac30ba8f8b6a8c55c2eb5461d0b60424ccd0db835662d1
|
File details
Details for the file swarmauri_middleware_logging-0.8.0.dev46-py3-none-any.whl.
File metadata
- Download URL: swarmauri_middleware_logging-0.8.0.dev46-py3-none-any.whl
- Upload date:
- Size: 8.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.10.12 {"installer":{"name":"uv","version":"0.10.12","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
924754866ed899b6be3be0d92f1e9f510a569f53b1d83e1e9530e0ada528bdae
|
|
| MD5 |
f1963abef89089f9c3a26fb6acd30bd1
|
|
| BLAKE2b-256 |
7aa2c09db1d50495745b637b344b3f9a3e521d48a50fc03e5999b2e6c293065f
|