Skip to content

Commit a94781d

Browse files
authored
Set propagate to False on "uvicorn" logger (#1288)
1 parent bfc8fb3 commit a94781d

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

tests/conftest.py

+11
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,17 @@
1515

1616
from uvicorn.config import LOGGING_CONFIG
1717

18+
# Note: We explicitly turn the propagate on just for tests, because pytest
19+
# caplog not able to capture no-propagate loggers.
20+
#
21+
# And the caplog_for_logger helper also not work on test config cases, because
22+
# when create Config object, Config.configure_logging will remove caplog.handler.
23+
#
24+
# The simple solution is set propagate=True before execute tests.
25+
#
26+
# See also: https://github.com/pytest-dev/pytest/issues/3697
27+
LOGGING_CONFIG["loggers"]["uvicorn"]["propagate"] = True
28+
1829

1930
@pytest.fixture
2031
def tls_certificate_authority() -> trustme.CA:

uvicorn/config.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@
118118
},
119119
},
120120
"loggers": {
121-
"uvicorn": {"handlers": ["default"], "level": "INFO"},
121+
"uvicorn": {"handlers": ["default"], "level": "INFO", "propagate": False},
122122
"uvicorn.error": {"level": "INFO"},
123123
"uvicorn.access": {"handlers": ["access"], "level": "INFO", "propagate": False},
124124
},

0 commit comments

Comments
 (0)