add rainbow logging with rich

This commit is contained in:
Jakub Miazek
2023-04-28 13:54:06 +02:00
parent 63014e11db
commit 1d98c7e39c
3 changed files with 58 additions and 44 deletions

View File

@@ -50,6 +50,27 @@ Data set is coming form https://github.com/catherinedevlin/opensourceshakespeare
Next models were generated with https://github.com/agronholm/sqlacodegen
And after some tweaking I got desired result
### Rainbow logs with rich :rainbow:
To deliver better user(developer) experience when watching logs with tons of information
from few emitters (which are really needy on development stage) project is using [rich](https://github.com/Textualize/rich) library.
Event with [rich](https://github.com/Textualize/rich) superpowers reading logs is not easy.
Found [rich](https://github.com/Textualize/rich) really nice -
but it took time to learn how to integrate it as logger object properly and keep it as singleton.
To address below needs:
- it is hard to find what I am looking for even with glasses on.
- dont want to hire ELK to be able to use logs.
- want to move fast enough with debugging.
Below steps were done to integrate [rich](https://github.com/Textualize/rich) into project.
1. Configure emitters with [config.ini](https://github.com/grillazz/fastapi-sqlalchemy-asyncpg/blob/main/config.ini)
2. Eliminate duplicates i.e. sqlalchemy echo by separate handlers
3. Keep logger as singleton pattern to avoid multiple instances
4. add uvicorn parameter --log-config config.ini
![sample-logs-with-rich](/static/logz.jpg)
Hope you enjoy it.
### Change Log