Delgan / loguru

Python logging made (stupidly) simple

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

gunicorn fastapi use loguru

fanmaoyu0871 opened this issue · comments

I used this command to deploy the fastapi gunicorn main:app -b 0.0.0.0:12000 -w 4 -k uvicorn.workers.UvicornWorker --daemon ,Logoru was used to record HTTP requests and responses, but I found that some logs were not recorded,my loguru config:logger.add("logs/api.log", encoding="utf-8", catch=True, backtrace=True, diagnose=True, enqueue=True, rotation="00:00", retention="20 days", compression="zip"),is -w 4 or -k uvicorn.workers.UvicornWorker has some problems?
use -w 1,it's likely work fine。

Yes, this is because of the multiple processes started by FastAPI. They won't inherit the logger, therefore the enqueue=True parameter is unfortunately ineffective.

Right now, it's advised to use one unique file per worker, until a new workaround is implemented in Loguru.

How to do it? Can you give me some ideas? Thank you