Skip to main content

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

Project description

asgi-logging-middleware

Latest Commit Build 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.0a2.tar.gz (4.5 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.0a2-py3-none-any.whl (5.6 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for asgi_logging_middleware-0.2.0a2.tar.gz
Algorithm Hash digest
SHA256 8e43b76ce3512acfc0accb595948a6666cad7ace53d64405274dc6d86a72cd9e
MD5 70e8e69a8cd4c699454b54ea355942be
BLAKE2b-256 d8c6a74900bc47b156055a61ff73d3be81553629ace090a24e9d95652aa89610

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for asgi_logging_middleware-0.2.0a2-py3-none-any.whl
Algorithm Hash digest
SHA256 508105e8b4660384bf6d283b553c73a28f7769bd1623dcb7edca7377112d770d
MD5 65554cf7f9b54d9d5f26e506d46991fa
BLAKE2b-256 a87f7c7bba4ea3f0835911021f80f06fe22dbc02f9c8adf85556e17222a4d228

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