Access logger for ASGI servers! :tada:
This project was created as an alternative for the current uvicorn logger. But it can also be used with any other ASGI server.
pip install asgi-logger
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.
This project is licensed under the terms of the MIT license.