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

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.0a1.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.0a1-py3-none-any.whl (5.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: asgi_logging_middleware-0.2.0a1.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.0a1.tar.gz
Algorithm Hash digest
SHA256 2d4c3cbb0b9ef4b49b644e5b8202e14adb1874ec341fce0e49e3fb6952dd3e81
MD5 1681b86ec87a6d768e7e08ec836744db
BLAKE2b-256 e090bfa252e3d9eef4603b0046a393c5243b210faa924e33ad576b58c3758279

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for asgi_logging_middleware-0.2.0a1-py3-none-any.whl
Algorithm Hash digest
SHA256 6038342aa09848bb159a09cf1c22c5383f8fa40862569ba3e51a46266e9fc6e3
MD5 ebb75c4037b7fea018b4272374823df8
BLAKE2b-256 2fdb5f5c722e7281d3be6bb24b41d98b3881a816d16ceb4bee7427e65e1da4b7

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