Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gunicorn fastapi use loguru #1111

Open
fanmaoyu0871 opened this issue Mar 28, 2024 · 3 comments
Open

gunicorn fastapi use loguru #1111

fanmaoyu0871 opened this issue Mar 28, 2024 · 3 comments

Comments

@fanmaoyu0871
Copy link

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。

@Delgan
Copy link
Owner

Delgan commented Mar 30, 2024

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.

@fanmaoyu0871
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants