Skip to main content

ASGI middleware for logging HTTP requests and responses. Fork of asgi-logger.

Project description

asgi-logging-middleware

Latest Commit Tests Status Code Coverage
Package version Python Version

Overview

This project was created as a fork of asgi-logger project.

ASGI logging middleware logs HTTP request/response data in a configurable format, similar to how web servers like Nginx or Apache log requests. Initially it was created as an alternative for the uvicorn access logger.

Primarily the middleware is targeted at Starlette and FastAPI applications, but it can be used with any ASGI application.

Installation

pip install asgi-logging-middleware

Usage

If you're using it with uvicorn, remember that you need to erase the handlers from uvicorn's logger that is writing the access logs. To do that, just:

logging.getLogger("uvicorn.access").handlers = []

Below you can see an example with FastAPI, but you can use it with any other ASGI application:

from fastapi import FastAPI
from fastapi.middleware import Middleware
from asgi_logging_middleware import AccessLoggerMiddleware

app = FastAPI(middleware=[Middleware(AccessLoggerMiddleware)])


@app.get("/")
async def home():
    return "Hello world!"

In case you want to add a custom format to the access logs, you can do it using the format parameter on the AccessLoggerMiddleware:

AccessLoggerMiddleware(app, format="%(s)s")

For now you can verify the possible format values here. The documentation will be available soon.

License

This project is licensed under the terms of the MIT license.

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

asgi_logging_middleware-0.2.0.tar.gz (4.6 kB view details)

Uploaded Source

Built Distribution

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

asgi_logging_middleware-0.2.0-py3-none-any.whl (5.6 kB view details)

Uploaded Python 3

File details

Details for the file asgi_logging_middleware-0.2.0.tar.gz.

File metadata

  • Download URL: asgi_logging_middleware-0.2.0.tar.gz
  • Upload date:
  • Size: 4.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.2.1 CPython/3.10.19 Linux/6.8.0-87-generic

File hashes

Hashes for asgi_logging_middleware-0.2.0.tar.gz
Algorithm Hash digest
SHA256 ced180af0eb04fce89ede1da6f1259e72d5c6e70cf0b1a6c757c4549b9c4b0ad
MD5 34dfbbc5e9cd899eae80cb16a807bcf7
BLAKE2b-256 3723def9270529eaa8c6586c463999ad9453a7dcee6793838704d33bd0b30d2f

See more details on using hashes here.

File details

Details for the file asgi_logging_middleware-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for asgi_logging_middleware-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e423593bb12624613fbfdeefe871ea1ef4f52f1fe4515b5fd55d541cc9e35086
MD5 8594813e3b857dfab7524e9987d25fa2
BLAKE2b-256 db6179f585590a4e9e76178ac627942108e76a4a3fe88ceb7617f92c322d0e6c

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