asgi-logger is a middleware-based access logger designed for ASGI servers, offering an alternative to the default Uvicorn logger. It is compatible with any ASGI application and provides customizable log formats. The current version is 0.1.0, released in November 2021, with development continuing on GitHub though without frequent PyPI releases.
pip install asgi-loggerVerified import paths — ran on the pinned version, not inferred.
This example demonstrates integrating `asgi-logger` with a FastAPI application. It shows how to add the `AccessLoggerMiddleware` with a custom format and, crucially, how to disable Uvicorn's built-in access logger to prevent redundant log entries.
Add `logging.getLogger("uvicorn.access").handlers = []` to your application's startup code.Ensure you are installing `asgi-logger` and importing `AccessLoggerMiddleware` from `asgi_logger`.
Check the GitHub issues for potential workarounds or newer versions addressing these specific bugs. You might need to adjust your log parsing or consider alternative logging approaches if these are critical.
Ensure all logging is configured to work within the asynchronous ASGI context, ideally using standard Python `logging` or an ASGI-aware logger. If using Flask with Uvicorn, consider using a wrapper or ensuring Flask's logger doesn't interfere.
This is an unresolved issue in the current version. Monitor the `asgi-logger` GitHub repository for updates or workarounds. For now, careful error handling around the middleware or a custom middleware to catch such `KeyError` might be needed.
Disable Uvicorn's default access logger by adding `logging.getLogger("uvicorn.access").handlers = []` to your application's entry point, before Uvicorn starts.