1818from .task import MessageSender , TaskSupervisor
1919from .telemetry import span_context
2020
21+ _logger = logging .getLogger (__name__ )
22+
2123JsonValue = Any
2224MethodHandler = Callable [[str , JsonValue | None , bool ], Awaitable [JsonValue | None ]]
2325
@@ -107,7 +109,7 @@ async def main_loop(self) -> None:
107109 try :
108110 await self ._receive_loop ()
109111 except Exception as exc :
110- logging .exception ("Connection main loop failed" , exc_info = exc )
112+ _logger .exception ("Connection main loop failed" , exc_info = exc )
111113 self ._on_receive_error (None , exc ) # type: ignore[arg-type]
112114 raise
113115
@@ -190,7 +192,7 @@ def _notify_observers(self, direction: StreamDirection, message: dict[str, Any])
190192 try :
191193 result = observer (event )
192194 except Exception :
193- logging .exception ("Stream observer failed" , exc_info = True )
195+ _logger .exception ("Stream observer failed" , exc_info = True )
194196 continue
195197 if inspect .isawaitable (result ):
196198 self ._tasks .create (
@@ -200,7 +202,7 @@ def _notify_observers(self, direction: StreamDirection, message: dict[str, Any])
200202 )
201203
202204 def _on_observer_error (self , task : asyncio .Task [Any ], exc : BaseException ) -> None :
203- logging .exception ("Stream observer coroutine failed" , exc_info = exc )
205+ _logger .exception ("Stream observer coroutine failed" , exc_info = exc )
204206
205207 def _track_incoming (self , request_id : Any , task : asyncio .Task [Any ]) -> None :
206208 # A ``$/cancel_request`` can only name a valid request id, and Python would alias an invalid
@@ -237,7 +239,7 @@ def _send_cancel_request(self, request_id: int) -> None:
237239 )
238240
239241 def _on_cancel_request_error (self , task : asyncio .Task [Any ], exc : BaseException ) -> None :
240- logging .debug ("Failed to send %s" , _CANCEL_REQUEST_METHOD , exc_info = exc )
242+ _logger .debug ("Failed to send %s" , _CANCEL_REQUEST_METHOD , exc_info = exc )
241243
242244 async def _run_request (
243245 self , message : dict [str , Any ], handler : asyncio .Future [dict [str , Any ]] | None = None
@@ -257,7 +259,7 @@ async def _run_request(
257259 except ConnectionError :
258260 if self ._closed or self ._disconnected :
259261 # The connection went away while the handler was running; nobody can receive it.
260- logging .debug ("Dropping response for request %r: connection closed" , message ["id" ])
262+ _logger .debug ("Dropping response for request %r: connection closed" , message ["id" ])
261263 return
262264 raise
263265 self ._notify_observers (StreamDirection .OUTGOING , payload )
@@ -284,7 +286,7 @@ async def _execute_request(self, message: dict[str, Any]) -> dict[str, Any]:
284286 except ValidationError as exc :
285287 payload ["error" ] = RequestError .invalid_params ({"errors" : exc .errors ()}).to_error_obj ()
286288 except Exception as exc :
287- logging .exception (
289+ _logger .exception (
288290 "Unhandled error while handling request method=%s" ,
289291 method ,
290292 exc_info = exc ,
@@ -302,7 +304,7 @@ async def _run_notification(self, message: dict[str, Any]) -> None:
302304 try :
303305 await self ._handler (method , message .get ("params" ), True )
304306 except Exception as exc :
305- logging .exception (
307+ _logger .exception (
306308 "Unhandled error while handling notification method=%s" ,
307309 method ,
308310 exc_info = exc ,
@@ -335,11 +337,11 @@ def _handle_response(self, message: dict[str, Any]) -> None:
335337 self ._pending .pop (request_id , None )
336338
337339 def _on_receive_error (self , task : asyncio .Task [Any ], exc : BaseException ) -> None :
338- logging .exception ("Receive loop failed" , exc_info = exc )
340+ _logger .exception ("Receive loop failed" , exc_info = exc )
339341 self ._disconnect ()
340342
341343 def _on_task_error (self , task : asyncio .Task [Any ], exc : BaseException ) -> None :
342- logging .exception ("Background task failed" , exc_info = exc )
344+ _logger .exception ("Background task failed" , exc_info = exc )
343345
344346 def _disconnect (self ) -> None :
345347 if self ._disconnected :
0 commit comments