Log formatter partially ignored with multiple workers #2673
Unanswered
geokarak
asked this question in
Potential Issue
Replies: 1 comment
-
|
This happens because uvicorn makes its own default logger configuration. In the case of a single worker, it looks like your dictConfig runs before uvicorn writes the first log, so everything is fine, but in the case of multiple workers, this does not work. I would suggest putting your logger configuration into a file and specifying it using cli: // log_config.json
{
"version": 1,
"disable_existing_loggers": true,
"formatters": {
"standard": {"format": "%(asctime)s [%(levelname)s] %(name)s: %(message)s"}
},
"handlers": {
"default": {
"level": "INFO",
"formatter": "standard",
"class": "logging.StreamHandler",
"stream": "ext://sys.stdout"
}
},
"loggers": {
"": {
"handlers": ["default"],
"level": "WARNING",
"propagate": false
},
"uvicorn.error": {"handlers": ["default"], "level": "INFO", "propagate": false},
"uvicorn.access": {
"handlers": ["default"],
"level": "INFO",
"propagate": false
}
}
}uvicorn myapp.main:app --log-config log_config.json --workers 2 |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I noticed that my custom log formatter for
uvicorn.erroris partially ignored when I start my (FastAPI) app with multiple workers. This behaviour is best visualized with the following screenshot:From the above picture, one can see that when using multiple workers, it seems that my log formatter is partially applied (middle block where logs start with a timestamp).
Reproduce issue
The structure of my dummy editable application is as follows:
where
and
I should note that, when calling uvicorn programmatically with
uvicorn.run("myapp.main:app", log_config=LOGGING_CONFIG, workers=2)insidemain.py, all logs are formatted appropriately. I could only see this issue when I run the app from the command line withuvicorn myapp.main:app --workers 2as shown in the initial screenshot.Beta Was this translation helpful? Give feedback.
All reactions