Metadata-Version: 2.4
Name: swarmauri_middleware_logging
Version: 0.11.0.dev1
Summary: Logging middleware for Swarmauri
License-Expression: Apache-2.0
License-File: LICENSE
Keywords: swarmauri,sdk,standards,middleware,logging
Author: Jacob Stewart
Author-email: jacob@swarmauri.com
Requires-Python: >=3.10,<3.15
Classifier: License :: OSI Approved :: Apache Software License
Classifier: Natural Language :: English
Classifier: Development Status :: 3 - Alpha
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Requires-Dist: fastapi
Requires-Dist: swarmauri_base
Requires-Dist: swarmauri_core
Requires-Dist: swarmauri_standard
Description-Content-Type: text/markdown

![Swarmauri Logo](https://raw.githubusercontent.com/swarmauri/swarmauri-sdk/master/assets/swarmauri_sdk_brand.png)

<p align="center">
    <a href="https://pepy.tech/project/swarmauri_middleware_logging/">
        <img src="https://static.pepy.tech/badge/swarmauri_middleware_logging/month" alt="PyPI - Downloads"/></a>
    <a href="https://hits.sh/github.com/swarmauri/swarmauri-sdk/tree/master/pkgs/standards/swarmauri_middleware_logging/">
        <img alt="Hits" src="https://hits.sh/github.com/swarmauri/swarmauri-sdk/tree/master/pkgs/standards/swarmauri_middleware_logging.svg"/></a>
    <a href="https://pypi.org/project/swarmauri_middleware_logging/">
        <img src="https://img.shields.io/badge/python-3.10%20%7C%203.11%20%7C%203.12%20%7C%203.13%20%7C%203.14-blue" alt="PyPI - Python Version"/></a>
    <a href="https://pypi.org/project/swarmauri_middleware_logging/">
        <img src="https://img.shields.io/pypi/l/swarmauri_middleware_logging" alt="PyPI - License"/></a>
    <a href="https://pypi.org/project/swarmauri_middleware_logging/">
        <img src="https://img.shields.io/pypi/v/swarmauri_middleware_logging?label=swarmauri_middleware_logging&color=green" alt="PyPI - swarmauri_middleware_logging"/></a>
    <a href="https://discord.gg/N4UpBuQv8T">
        <img src="https://img.shields.io/badge/Discord-Join%20Chat-5865F2?logo=discord&logoColor=white" alt="Discord"/></a></p>

# 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:

```bash
pip install swarmauri_middleware_logging
```

```bash
poetry add swarmauri_middleware_logging
```

```bash
uv pip install swarmauri_middleware_logging
```

```bash
uv add swarmauri_middleware_logging
```

## Example

```python
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](https://github.com/swarmauri/swarmauri-sdk/blob/master/CONTRIBUTING.md) that will help you get started.



