Share a solution about adding single file logging handler instance for both app loggers and uvicorn loggers #11225
boholder
started this conversation in
Show and tell
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
boholder/python_web_server_template@006cdc6
Quite a trick but it works. I don't want to create two file logging handlers for one same file, although it works but I'm not sure if this solution is reliable under heavy workload.
How the trick works:
uvicorn.config.LOGGING_CONFIG
.uvicorn
starts and initializes the file handler instance.if __name__ == "__main__": uvicorn.run("main:app", port=8000, reload=True)
fastapi
's lifecycle function, setHope it helps.
PS: Please DO separate fastapi app instance from main module (where calls
uvicorn.run()
) to ensure there is only one app instance is generatedboholder/python_web_server_template@393d573
Beta Was this translation helpful? Give feedback.
All reactions