@@ -143,19 +143,19 @@ async def monitor_current_session(self) -> None:
143143 session : ClientWebSocketResponse = self .current_session # type: ignore[assignment]
144144 session_id : str = self .build_session_id (session )
145145
146- if self .logger .level <= logging .DEBUG :
146+ if self .logger .isEnabledFor ( logging .DEBUG ) :
147147 self .logger .debug (f"A new monitor_current_session() execution loop for { session_id } started" )
148148 try :
149149 logging_interval = 100
150150 counter_for_logging = 0
151151
152152 while not self .closed :
153153 if session != self .current_session :
154- if self .logger .level <= logging .DEBUG :
154+ if self .logger .isEnabledFor ( logging .DEBUG ) :
155155 self .logger .debug (f"The monitor_current_session task for { session_id } is now cancelled" )
156156 break
157157 try :
158- if self .trace_enabled and self .logger .level <= logging .DEBUG :
158+ if self .trace_enabled and self .logger .isEnabledFor ( logging .DEBUG ) :
159159 # The logging here is for detailed investigation on potential issues in this client.
160160 # If you don't see this log for a while, it means that
161161 # this receive_messages execution is no longer working for some reason.
@@ -207,7 +207,7 @@ async def monitor_current_session(self) -> None:
207207 f"(error: { type (e ).__name__ } , message: { e } )"
208208 )
209209 except asyncio .CancelledError :
210- if self .logger .level <= logging .DEBUG :
210+ if self .logger .isEnabledFor ( logging .DEBUG ) :
211211 self .logger .debug (f"The monitor_current_session task for { session_id } is now cancelled" )
212212 raise
213213
@@ -217,7 +217,7 @@ async def receive_messages(self) -> None:
217217 # To avoid such, we access only the session that is active when this loop starts.
218218 session = self .current_session
219219 session_id = self .build_session_id (session ) # type: ignore[arg-type]
220- if self .logger .level <= logging .DEBUG :
220+ if self .logger .isEnabledFor ( logging .DEBUG ) :
221221 self .logger .debug (f"A new receive_messages() execution loop with { session_id } started" )
222222 try :
223223 consecutive_error_count = 0
@@ -226,14 +226,14 @@ async def receive_messages(self) -> None:
226226
227227 while not self .closed :
228228 if session != self .current_session :
229- if self .logger .level <= logging .DEBUG :
229+ if self .logger .isEnabledFor ( logging .DEBUG ) :
230230 self .logger .debug (f"The running receive_messages task for { session_id } is now cancelled" )
231231 break
232232 try :
233233 message : WSMessage = await session .receive () # type: ignore[union-attr]
234234 # just in case, checking if the value is not None
235235 if message is not None :
236- if self .logger .level <= logging .DEBUG :
236+ if self .logger .isEnabledFor ( logging .DEBUG ) :
237237 # The following logging prints every single received message
238238 # except empty message data ones.
239239 m_type = WSMsgType (message .type )
@@ -308,7 +308,7 @@ async def receive_messages(self) -> None:
308308 else :
309309 await asyncio .sleep (consecutive_error_count )
310310 except asyncio .CancelledError :
311- if self .logger .level <= logging .DEBUG :
311+ if self .logger .isEnabledFor ( logging .DEBUG ) :
312312 self .logger .debug (f"The running receive_messages task for { session_id } is now cancelled" )
313313 raise
314314
@@ -326,7 +326,7 @@ async def is_connected(self) -> bool:
326326 and not self .current_session .closed
327327 and not await self .is_ping_pong_failing ()
328328 )
329- if self .logger .level <= logging .DEBUG and connected is False :
329+ if self .logger .isEnabledFor ( logging .DEBUG ) and connected is False :
330330 # Prints more detailed information about the inactive connection
331331 is_ping_pong_failing = await self .is_ping_pong_failing ()
332332 session_id = await self .session_id ()
@@ -387,26 +387,26 @@ async def connect(self):
387387 self .logger .info (f"A new session ({ session_id } ) has been established" )
388388
389389 # The first ping from the new connection
390- if self .logger .level <= logging .DEBUG :
390+ if self .logger .isEnabledFor ( logging .DEBUG ) :
391391 self .logger .debug (f"Sending a ping message with the newly established connection ({ session_id } )..." )
392392 t = time .time ()
393393 await self .current_session .ping (f"sdk-ping-pong:{ t } " .encode ("utf-8" ))
394394
395395 if self .current_session_monitor is not None :
396396 self .current_session_monitor .cancel ()
397397 self .current_session_monitor = asyncio .ensure_future (self .monitor_current_session ())
398- if self .logger .level <= logging .DEBUG :
398+ if self .logger .isEnabledFor ( logging .DEBUG ) :
399399 self .logger .debug (f"A new monitor_current_session() executor has been recreated for { session_id } " )
400400
401401 if self .message_receiver is not None :
402402 self .message_receiver .cancel ()
403403 self .message_receiver = asyncio .ensure_future (self .receive_messages ())
404- if self .logger .level <= logging .DEBUG :
404+ if self .logger .isEnabledFor ( logging .DEBUG ) :
405405 self .logger .debug (f"A new receive_messages() executor has been recreated for { session_id } " )
406406 break
407407 except Exception as e :
408408 if self .closed :
409- if self .logger .level <= logging .DEBUG :
409+ if self .logger .isEnabledFor ( logging .DEBUG ) :
410410 self .logger .debug (f"Stopped connecting because the client is closed (error: { e } )" )
411411 return
412412 self .logger .exception (f"Failed to connect (error: { e } ); Retrying..." )
@@ -420,14 +420,14 @@ async def disconnect(self):
420420
421421 async def send_message (self , message : str ):
422422 session_id = await self .session_id ()
423- if self .logger .level <= logging .DEBUG :
423+ if self .logger .isEnabledFor ( logging .DEBUG ) :
424424 self .logger .debug (f"Sending a message: { message } from session: { session_id } " )
425425 try :
426426 await self .current_session .send_str (message ) # type: ignore[union-attr]
427427 except ConnectionError as e :
428428 # We rarely get this exception while replacing the underlying WebSocket connections.
429429 # We can do one more try here as the self.current_session should be ready now.
430- if self .logger .level <= logging .DEBUG :
430+ if self .logger .isEnabledFor ( logging .DEBUG ) :
431431 self .logger .debug (
432432 f"Failed to send a message (error: { e } , message: { message } , session: { session_id } )"
433433 " as the underlying connection was replaced. Retrying the same request only one time..."
0 commit comments