feat: allow using UVICORN_LOG_CONFIG env var to be used to configure uvicorn logging. #882
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Motivation
The reason for this PR is that I'm having issues configuring all the loggers, and this causes problems with some log messages being in a different format than expected; We want all our logging to be json such that it can be ingested into our logging aggregator as a single blob, but with the default logging config that cannot be overridden currently we instead sometimes get a bunch of separate log messages that can't be ingested as a single blob and are missing important fields.
Implementation
We let
UVICORN_LOG_CONFIG
be loaded from the environment, its default value isuvicorn.config.LOGGING_CONFIG
(unsure how to handle this best really, either we need a reference touvicorn.config.LOGGING_CONFIG
or it should instead not set thelog_config
kwarg in theuvicorn.Config
if it's not set, which would then fallback to theuvicorn
default value; because if we set it to None then it won't use the default logging config). This config value is then passed touvicorn.Config
which is used to configure theuvicorn
server.The value of
UVICORN_LOG_CONFIG
could belogging.conf
, andlogging.conf
could look something like this:Questions
To ensure that logging isn't configured multiple times.