Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/kludex/asgi-logger
Access logger for ASGI servers! :tada:
https://github.com/kludex/asgi-logger
asgi asgi-middleware logger uvicorn
Last synced: about 2 months ago
JSON representation
Access logger for ASGI servers! :tada:
- Host: GitHub
- URL: https://github.com/kludex/asgi-logger
- Owner: Kludex
- License: mit
- Created: 2021-10-11T21:09:33.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2024-01-05T12:11:02.000Z (about 1 year ago)
- Last Synced: 2024-12-10T03:32:13.198Z (about 2 months ago)
- Topics: asgi, asgi-middleware, logger, uvicorn
- Language: Python
- Homepage:
- Size: 138 KB
- Stars: 48
- Watchers: 2
- Forks: 8
- Open Issues: 15
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
asgi-logger
This project was created as an alternative for the current uvicorn logger. But it can also be used with any other ASGI server.
## Installation
``` bash
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:```python
logging.getLogger("uvicorn.access").handlers = []
```Below you can see an example with FastAPI, but you can use it with any other ASGI application:
```python
from fastapi import FastAPI
from fastapi.middleware import Middleware
from asgi_logger import AccessLoggerMiddlewareapp = 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`:
```python
AccessLoggerMiddleware(app, format="%(s)s")
```For now you can verify the possible format values [here](https://github.com/Kludex/asgi-logger/blob/main/asgi_logger/middleware.py).
The documentation will be available soon.## License
This project is licensed under the terms of the MIT license.