asgi logger

Access logger for ASGI servers! :tada:

48
8
Python

asgi-logger

Latest Commit
Package version

This project was created as an alternative for the current uvicorn logger. But it can also be used with any other ASGI server.

Installation

pip install asgi-logger

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_logger 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.