Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

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:

Awesome Lists containing this project

README

        


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

``` 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 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`:

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