diff --git a/tests/middleware/test_logging.py b/tests/middleware/test_logging.py index 6c8dca4c60..bbb61e1f59 100644 --- a/tests/middleware/test_logging.py +++ b/tests/middleware/test_logging.py @@ -57,7 +57,7 @@ async def test_trace_logging_on_http_protocol(http_protocol, caplog, logging_con http=http_protocol, log_config=logging_config, ) - with caplog_for_logger(caplog, "uvicorn.error"): + with caplog_for_logger(caplog, "uvicorn.server"): async with run_server(config): async with httpx.AsyncClient() as client: response = await client.get("http://127.0.0.1:8000") @@ -65,7 +65,7 @@ async def test_trace_logging_on_http_protocol(http_protocol, caplog, logging_con messages = [ record.message for record in caplog.records - if record.name == "uvicorn.error" + if record.name == "uvicorn.server" ] assert any(" - HTTP connection made" in message for message in messages) assert any(" - HTTP connection lost" in message for message in messages) @@ -93,14 +93,14 @@ async def open_connection(url): log_config=logging_config, ws=ws_protocol, ) - with caplog_for_logger(caplog, "uvicorn.error"): + with caplog_for_logger(caplog, "uvicorn.websockets"): async with run_server(config): is_open = await open_connection("ws://127.0.0.1:8000") assert is_open messages = [ record.message for record in caplog.records - if record.name == "uvicorn.error" + if record.name == "uvicorn.websockets" ] assert any(" - Upgrading to WebSocket" in message for message in messages) assert any(" - WebSocket connection made" in message for message in messages) diff --git a/tests/protocols/test_http.py b/tests/protocols/test_http.py index 876fcf076d..2daf47e6ea 100644 --- a/tests/protocols/test_http.py +++ b/tests/protocols/test_http.py @@ -741,8 +741,8 @@ def test_invalid_http_request(request_line, protocol_cls, caplog, event_loop): app = Response("Hello, world", media_type="text/plain") request = INVALID_REQUEST_TEMPLATE % request_line - caplog.set_level(logging.INFO, logger="uvicorn.error") - logging.getLogger("uvicorn.error").propagate = True + caplog.set_level(logging.INFO, logger="uvicorn.http") + logging.getLogger("uvicorn.http").propagate = True with get_connected_protocol(app, protocol_cls, event_loop) as protocol: protocol.data_received(request) diff --git a/tests/supervisors/test_reload.py b/tests/supervisors/test_reload.py index 81e770b410..c8884ae41a 100644 --- a/tests/supervisors/test_reload.py +++ b/tests/supervisors/test_reload.py @@ -365,7 +365,7 @@ def test_should_detect_new_exclude_dirs( app="tests.test_config:asgi_app", reload=True, reload_excludes=["app*"] ) reloader = self._setup_reloader(config) - caplog.set_level(DEBUG, logger="uvicorn.error") + caplog.set_level(DEBUG, logger="uvicorn.server") assert not self._reload_tester(reloader, app_file) diff --git a/tests/test_config.py b/tests/test_config.py index 39fd747428..be36bb83b6 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -260,7 +260,7 @@ def test_app_unimportable_other(caplog: pytest.LogCaptureFixture) -> None: error_messages = [ record.message for record in caplog.records - if record.name == "uvicorn.error" and record.levelname == "ERROR" + if record.name == "uvicorn.server" and record.levelname == "ERROR" ] assert ( 'Error loading ASGI app. Attribute "app" not found in module "tests.test_config".' # noqa: E501 @@ -491,8 +491,10 @@ def test_config_log_level(log_level: int) -> None: config = Config(app=asgi_app, log_level=log_level) config.load() - assert logging.getLogger("uvicorn.error").level == log_level + assert logging.getLogger("uvicorn.server").level == log_level assert logging.getLogger("uvicorn.access").level == log_level + assert logging.getLogger("uvicorn.http").level == log_level + assert logging.getLogger("uvicorn.websockets").level == log_level assert logging.getLogger("uvicorn.asgi").level == log_level assert config.log_level == log_level diff --git a/tests/test_lifespan.py b/tests/test_lifespan.py index d49a9dcf93..0a78ac2d28 100644 --- a/tests/test_lifespan.py +++ b/tests/test_lifespan.py @@ -155,7 +155,7 @@ async def test(): error_messages = [ record.message for record in caplog.records - if record.name == "uvicorn.error" and record.levelname == "ERROR" + if record.name == "uvicorn.server" and record.levelname == "ERROR" ] assert "the lifespan event failed" in error_messages.pop(0) assert "Application startup failed. Exiting." in error_messages.pop(0) @@ -240,7 +240,7 @@ async def test(): error_messages = [ record.message for record in caplog.records - if record.name == "uvicorn.error" and record.levelname == "ERROR" + if record.name == "uvicorn.server" and record.levelname == "ERROR" ] assert "the lifespan event failed" in error_messages.pop(0) assert "Application shutdown failed. Exiting." in error_messages.pop(0) diff --git a/tests/test_main.py b/tests/test_main.py index 2ff72bc0eb..21a27e9e7b 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -89,7 +89,7 @@ def test_run_invalid_app_config_combination(caplog: pytest.LogCaptureFixture) -> with pytest.raises(SystemExit) as exit_exception: run(app, reload=True) assert exit_exception.value.code == 1 - assert caplog.records[-1].name == "uvicorn.error" + assert caplog.records[-1].name == "uvicorn.server" assert caplog.records[-1].levelno == WARNING assert caplog.records[-1].message == ( "You must pass the application as an import string to enable " diff --git a/uvicorn/config.py b/uvicorn/config.py index c96f16691f..dcedce8b13 100644 --- a/uvicorn/config.py +++ b/uvicorn/config.py @@ -105,12 +105,14 @@ }, "loggers": { "uvicorn": {"handlers": ["default"], "level": "INFO"}, - "uvicorn.error": {"level": "INFO"}, + "uvicorn.server": {"level": "INFO"}, + "uvicorn.websockets": {"level": "INFO"}, + "uvicorn.http": {"level": "INFO"}, "uvicorn.access": {"handlers": ["access"], "level": "INFO", "propagate": False}, }, } -logger = logging.getLogger("uvicorn.error") +logger = logging.getLogger("uvicorn.server") def create_ssl_context( @@ -406,8 +408,10 @@ def configure_logging(self) -> None: log_level = LOG_LEVELS[self.log_level] else: log_level = self.log_level - logging.getLogger("uvicorn.error").setLevel(log_level) + logging.getLogger("uvicorn.server").setLevel(log_level) logging.getLogger("uvicorn.access").setLevel(log_level) + logging.getLogger("uvicorn.http").setLevel(log_level) + logging.getLogger("uvicorn.websockets").setLevel(log_level) logging.getLogger("uvicorn.asgi").setLevel(log_level) if self.access_log is False: logging.getLogger("uvicorn.access").handlers = [] diff --git a/uvicorn/lifespan/on.py b/uvicorn/lifespan/on.py index caf6e505ec..cf430f8624 100644 --- a/uvicorn/lifespan/on.py +++ b/uvicorn/lifespan/on.py @@ -32,7 +32,7 @@ def __init__(self, config: Config) -> None: config.load() self.config = config - self.logger = logging.getLogger("uvicorn.error") + self.logger = logging.getLogger("uvicorn.server") self.startup_event = asyncio.Event() self.shutdown_event = asyncio.Event() self.receive_queue: "Queue[LifespanReceiveMessage]" = asyncio.Queue() diff --git a/uvicorn/loops/asyncio.py b/uvicorn/loops/asyncio.py index 9a9ed64951..7c762b0132 100644 --- a/uvicorn/loops/asyncio.py +++ b/uvicorn/loops/asyncio.py @@ -2,7 +2,7 @@ import logging import sys -logger = logging.getLogger("uvicorn.error") +logger = logging.getLogger("uvicorn.server") def asyncio_setup(reload: bool = False) -> None: # pragma: no cover diff --git a/uvicorn/main.py b/uvicorn/main.py index bfeeeb5848..0411f68308 100644 --- a/uvicorn/main.py +++ b/uvicorn/main.py @@ -37,7 +37,7 @@ STARTUP_FAILURE = 3 -logger = logging.getLogger("uvicorn.error") +logger = logging.getLogger("uvicorn.server") def print_version(ctx: click.Context, param: click.Parameter, value: bool) -> None: @@ -542,7 +542,7 @@ def run( server = Server(config=config) if (config.reload or config.workers > 1) and not isinstance(app, str): - logger = logging.getLogger("uvicorn.error") + logger = logging.getLogger("uvicorn.server") logger.warning( "You must pass the application as an import string to enable 'reload' or " "'workers'." diff --git a/uvicorn/protocols/http/h11_impl.py b/uvicorn/protocols/http/h11_impl.py index 1767f55970..0cb0cedb2f 100644 --- a/uvicorn/protocols/http/h11_impl.py +++ b/uvicorn/protocols/http/h11_impl.py @@ -74,7 +74,7 @@ def __init__( self.config = config self.app = config.loaded_app self.loop = _loop or asyncio.get_event_loop() - self.logger = logging.getLogger("uvicorn.error") + self.logger = logging.getLogger("uvicorn.http") self.access_logger = logging.getLogger("uvicorn.access") self.access_log = self.access_logger.hasHandlers() self.conn = h11.Connection(h11.SERVER) diff --git a/uvicorn/protocols/http/httptools_impl.py b/uvicorn/protocols/http/httptools_impl.py index e932b74b04..d010268ec2 100644 --- a/uvicorn/protocols/http/httptools_impl.py +++ b/uvicorn/protocols/http/httptools_impl.py @@ -72,7 +72,7 @@ def __init__( self.config = config self.app = config.loaded_app self.loop = _loop or asyncio.get_event_loop() - self.logger = logging.getLogger("uvicorn.error") + self.logger = logging.getLogger("uvicorn.http") self.access_logger = logging.getLogger("uvicorn.access") self.access_log = self.access_logger.hasHandlers() self.parser = httptools.HttpRequestParser(self) diff --git a/uvicorn/protocols/websockets/websockets_impl.py b/uvicorn/protocols/websockets/websockets_impl.py index 7161e72141..39bf34e526 100644 --- a/uvicorn/protocols/websockets/websockets_impl.py +++ b/uvicorn/protocols/websockets/websockets_impl.py @@ -66,7 +66,7 @@ def __init__(self, config, server_state, _loop=None): ping_interval=self.config.ws_ping_interval, ping_timeout=self.config.ws_ping_timeout, extensions=extensions, - logger=logging.getLogger("uvicorn.error"), + logger=logging.getLogger("uvicorn.websockets"), extra_headers=[], ) diff --git a/uvicorn/protocols/websockets/wsproto_impl.py b/uvicorn/protocols/websockets/wsproto_impl.py index a2c205e510..1381332ef8 100644 --- a/uvicorn/protocols/websockets/wsproto_impl.py +++ b/uvicorn/protocols/websockets/wsproto_impl.py @@ -21,7 +21,7 @@ def __init__(self, config, server_state, _loop=None): self.config = config self.app = config.loaded_app self.loop = _loop or asyncio.get_event_loop() - self.logger = logging.getLogger("uvicorn.error") + self.logger = logging.getLogger("uvicorn.websockets") self.root_path = config.root_path # Shared server state diff --git a/uvicorn/server.py b/uvicorn/server.py index 494e2b658a..72678d3693 100644 --- a/uvicorn/server.py +++ b/uvicorn/server.py @@ -30,7 +30,7 @@ signal.SIGTERM, # Unix signal 15. Sent by `kill `. ) -logger = logging.getLogger("uvicorn.error") +logger = logging.getLogger("uvicorn.server") class ServerState: diff --git a/uvicorn/supervisors/basereload.py b/uvicorn/supervisors/basereload.py index 667633ee3f..bb29b9793f 100644 --- a/uvicorn/supervisors/basereload.py +++ b/uvicorn/supervisors/basereload.py @@ -16,7 +16,7 @@ signal.SIGTERM, # Unix signal 15. Sent by `kill `. ) -logger = logging.getLogger("uvicorn.error") +logger = logging.getLogger("uvicorn.server") class BaseReload: diff --git a/uvicorn/supervisors/multiprocess.py b/uvicorn/supervisors/multiprocess.py index 9ab4a742e6..7937d00225 100644 --- a/uvicorn/supervisors/multiprocess.py +++ b/uvicorn/supervisors/multiprocess.py @@ -17,7 +17,7 @@ signal.SIGTERM, # Unix signal 15. Sent by `kill `. ) -logger = logging.getLogger("uvicorn.error") +logger = logging.getLogger("uvicorn.server") class Multiprocess: diff --git a/uvicorn/supervisors/statreload.py b/uvicorn/supervisors/statreload.py index 8392e9f1f2..10141b62d7 100644 --- a/uvicorn/supervisors/statreload.py +++ b/uvicorn/supervisors/statreload.py @@ -6,7 +6,7 @@ from uvicorn.config import Config from uvicorn.supervisors.basereload import BaseReload -logger = logging.getLogger("uvicorn.error") +logger = logging.getLogger("uvicorn.server") class StatReload(BaseReload): diff --git a/uvicorn/supervisors/watchgodreload.py b/uvicorn/supervisors/watchgodreload.py index 223799b58f..32a71ddb1c 100644 --- a/uvicorn/supervisors/watchgodreload.py +++ b/uvicorn/supervisors/watchgodreload.py @@ -8,7 +8,7 @@ from uvicorn.config import Config from uvicorn.supervisors.basereload import BaseReload -logger = logging.getLogger("uvicorn.error") +logger = logging.getLogger("uvicorn.server") if TYPE_CHECKING: import os diff --git a/uvicorn/workers.py b/uvicorn/workers.py index f28c3a8d43..ccaf8e416a 100644 --- a/uvicorn/workers.py +++ b/uvicorn/workers.py @@ -22,7 +22,7 @@ class UvicornWorker(Worker): def __init__(self, *args: Any, **kwargs: Any) -> None: super(UvicornWorker, self).__init__(*args, **kwargs) - logger = logging.getLogger("uvicorn.error") + logger = logging.getLogger("uvicorn.server") logger.handlers = self.log.error_log.handlers logger.setLevel(self.log.error_log.level) logger.propagate = False