Accept log_level strings case-insensitively (#2907)

Co-authored-by: Nuno André <mail@nunoand.re>
This commit is contained in:
Marcelo Trylesinski 2026-04-19 12:00:23 +02:00 committed by GitHub
parent 70f247f9ee
commit fdcacb4b83
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 8 additions and 1 deletions

View File

@ -482,6 +482,13 @@ def test_config_log_effective_level(log_level: int, uvicorn_logger_level: int) -
assert logging.getLogger("uvicorn.asgi").getEffectiveLevel() == effective_level
@pytest.mark.parametrize("log_level", ["INFO", "Info", "info"])
def test_config_log_level_case_insensitive(log_level: str) -> None:
config = Config(app=asgi_app, log_level=log_level)
config.load()
assert logging.getLogger("uvicorn.error").level == logging.INFO
def test_ws_max_size() -> None:
config = Config(app=asgi_app, ws_max_size=1000)
config.load()

View File

@ -392,7 +392,7 @@ class Config:
if self.log_level is not None:
if isinstance(self.log_level, str):
log_level = LOG_LEVELS[self.log_level]
log_level = LOG_LEVELS[self.log_level.lower()]
else:
log_level = self.log_level
logging.getLogger("uvicorn.error").setLevel(log_level)