fix: respect log_level in uvicorn and third party libs

uvicorn has a `log_level` arg in uvicorn.run, pass in the effective level set by the logger.

Additionally, third party libraries like httpx are using our logging format, but not honoring our log level.

This seems unintended, so loop through all items in the loggerDict and apply the same log level as what we have set.

Signed-off-by: Charlie Doern <cdoern@redhat.com>
This commit is contained in:
Charlie Doern 2025-03-10 16:02:19 -04:00
parent 00da911167
commit 2dc458c4f6
2 changed files with 6 additions and 0 deletions

View file

@ -422,6 +422,7 @@ def main():
"host": listen_host,
"port": port,
"lifespan": "on",
"log_level": logger.getEffectiveLevel(),
}
if ssl_config:
uvicorn_config.update(ssl_config)

View file

@ -170,6 +170,11 @@ def setup_logging(category_levels: Dict[str, int], log_file: str | None) -> None
}
dictConfig(logging_config)
# Ensure third-party libraries follow the root log level
for _, logger in logging.root.manager.loggerDict.items():
if isinstance(logger, logging.Logger):
logger.setLevel(root_level)
def get_logger(name: str, category: str = "uncategorized") -> logging.LoggerAdapter:
"""