Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions slack_sdk/audit_logs/v1/async_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ async def _perform_http_request(
retry_response: Optional[RetryHttpResponse] = None
response_body = ""

if self.logger.level <= logging.DEBUG:
if self.logger.isEnabledFor(logging.DEBUG):
headers_for_logging = {
k: "(redacted)" if k.lower() == "authorization" else v for k, v in headers.items()
}
Expand Down Expand Up @@ -309,8 +309,8 @@ async def _perform_http_request(
response=retry_response,
error=e,
):
if self.logger.level <= logging.DEBUG:
self.logger.info(
if self.logger.isEnabledFor(logging.DEBUG):
self.logger.debug(
f"A retry handler found: {type(handler).__name__} "
f"for {http_verb} {url} - status: {res.status}"
)
Expand All @@ -320,6 +320,7 @@ async def _perform_http_request(
response=retry_response,
error=e,
)
self.logger.info(f"Going to retry the same request: {http_verb} {url}")
break

if retry_state.next_attempt_requested is False:
Expand All @@ -341,8 +342,8 @@ async def _perform_http_request(
response=retry_response,
error=e,
):
if self.logger.level <= logging.DEBUG:
self.logger.info(
if self.logger.isEnabledFor(logging.DEBUG):
self.logger.debug(
f"A retry handler found: {type(handler).__name__} for {http_verb} {url} - {e}"
)
await handler.prepare_for_next_attempt_async(
Expand All @@ -351,6 +352,7 @@ async def _perform_http_request(
response=retry_response,
error=e,
)
self.logger.info(f"Going to retry the same request: {http_verb} {url}")
break

if retry_state.next_attempt_requested is False:
Expand Down
11 changes: 6 additions & 5 deletions slack_sdk/audit_logs/v1/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ def _perform_http_request(
body = json.dumps(body) # type: ignore[assignment]
headers["Content-Type"] = "application/json;charset=utf-8"

if self.logger.level <= logging.DEBUG:
if self.logger.isEnabledFor(logging.DEBUG):
headers_for_logging = {k: "(redacted)" if k.lower() == "authorization" else v for k, v in headers.items()}
self.logger.debug(f"Sending a request - url: {url}, body: {body}, headers: {headers_for_logging}")

Expand Down Expand Up @@ -284,8 +284,8 @@ def _perform_http_request(
response=retry_response,
error=e,
):
if self.logger.level <= logging.DEBUG:
self.logger.info(
if self.logger.isEnabledFor(logging.DEBUG):
self.logger.debug(
f"A retry handler found: {type(handler).__name__} for {req.method} {req.full_url} - {e}"
)
handler.prepare_for_next_attempt(
Expand All @@ -294,6 +294,7 @@ def _perform_http_request(
response=retry_response,
error=e,
)
self.logger.info(f"Going to retry the same request: {req.method} {req.full_url}")
break

if retry_state.next_attempt_requested is False:
Expand All @@ -312,8 +313,8 @@ def _perform_http_request(
response=None,
error=err,
):
if self.logger.level <= logging.DEBUG:
self.logger.info(
if self.logger.isEnabledFor(logging.DEBUG):
self.logger.debug(
f"A retry handler found: {type(handler).__name__} for {req.method} {req.full_url} - {err}"
)
handler.prepare_for_next_attempt(
Expand Down
2 changes: 1 addition & 1 deletion slack_sdk/audit_logs/v1/internal_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def _build_request_headers(


def _debug_log_response(logger, resp: AuditLogsResponse) -> None:
if logger.level <= logging.DEBUG:
if logger.isEnabledFor(logging.DEBUG):
logger.debug(
"Received the following response - "
f"status: {resp.status_code}, "
Expand Down
8 changes: 4 additions & 4 deletions slack_sdk/oauth/installation_store/sqlite3/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ def find_bot(

except Exception as e:
message = f"Failed to find bot installation data for enterprise: {enterprise_id}, team: {team_id}: {e}"
if self.logger.level <= logging.DEBUG:
if self.logger.isEnabledFor(logging.DEBUG):
self.logger.exception(message)
else:
self.logger.warning(message)
Expand Down Expand Up @@ -530,7 +530,7 @@ def find_installation(

except Exception as e:
message = f"Failed to find an installation data for enterprise: {enterprise_id}, team: {team_id}: {e}"
if self.logger.level <= logging.DEBUG:
if self.logger.isEnabledFor(logging.DEBUG):
self.logger.exception(message)
else:
self.logger.warning(message)
Expand Down Expand Up @@ -559,7 +559,7 @@ def delete_bot(self, *, enterprise_id: Optional[str], team_id: Optional[str]) ->
conn.commit()
except Exception as e:
message = f"Failed to delete bot installation data for enterprise: {enterprise_id}, team: {team_id}: {e}"
if self.logger.level <= logging.DEBUG:
if self.logger.isEnabledFor(logging.DEBUG):
self.logger.exception(message)
else:
self.logger.warning(message)
Expand Down Expand Up @@ -617,7 +617,7 @@ def delete_installation(
conn.commit()
except Exception as e:
message = f"Failed to delete installation data for enterprise: {enterprise_id}, team: {team_id}: {e}"
if self.logger.level <= logging.DEBUG:
if self.logger.isEnabledFor(logging.DEBUG):
self.logger.exception(message)
else:
self.logger.warning(message)
2 changes: 1 addition & 1 deletion slack_sdk/rtm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ async def _dispatch_event(self, event, data=None):
}
}
"""
if self._logger.level <= logging.DEBUG:
if self._logger.isEnabledFor(logging.DEBUG):
self._logger.debug("Received an event: '%s' - %s", event, data)
for callback in self._callbacks[event]:
self._logger.debug(
Expand Down
12 changes: 6 additions & 6 deletions slack_sdk/rtm_v2/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,13 +286,13 @@ def send(self, payload: Union[dict, str]) -> None:

def enqueue_message(self, message: str):
self.message_queue.put(message)
if self.logger.level <= logging.DEBUG:
if self.logger.isEnabledFor(logging.DEBUG):
self.logger.debug(f"A new message enqueued (current queue size: {self.message_queue.qsize()})")

def process_message(self):
try:
raw_message = self.message_queue.get(timeout=1)
if self.logger.level <= logging.DEBUG:
if self.logger.isEnabledFor(logging.DEBUG):
self.logger.debug(f"A message dequeued (current queue size: {self.message_queue.qsize()})")

if raw_message is not None:
Expand All @@ -316,7 +316,7 @@ def process_messages(self) -> None:

def run_message_listeners(self, message: dict) -> None:
type = message.get("type")
if self.logger.level <= logging.DEBUG:
if self.logger.isEnabledFor(logging.DEBUG):
self.logger.debug(f"Message processing started (type: {type})")
try:
for listener in self.message_listeners:
Expand All @@ -327,7 +327,7 @@ def run_message_listeners(self, message: dict) -> None:
except Exception as e:
self.logger.exception(f"Failed to run message listeners: {e}")
finally:
if self.logger.level <= logging.DEBUG:
if self.logger.isEnabledFor(logging.DEBUG):
self.logger.debug(f"Message processing completed (type: {type})")

# --------------------------------------------------------------
Expand All @@ -340,7 +340,7 @@ def session_id(self) -> Optional[str]:
return None

def run_all_message_listeners(self, message: str):
if self.logger.level <= logging.DEBUG:
if self.logger.isEnabledFor(logging.DEBUG):
self.logger.debug(f"on_message invoked: (message: {message})")
self.enqueue_message(message)
for listener in self.on_message_listeners:
Expand All @@ -354,7 +354,7 @@ def run_all_error_listeners(self, error: Exception):
listener(error)

def run_all_close_listeners(self, code: int, reason: Optional[str] = None):
if self.logger.level <= logging.DEBUG:
if self.logger.isEnabledFor(logging.DEBUG):
self.logger.debug(f"on_close invoked (session id: {self.session_id()})")
if self.auto_reconnect_enabled:
self.logger.info(f"Received CLOSE event. Going to reconnect... (session id: {self.session_id()})")
Expand Down
12 changes: 7 additions & 5 deletions slack_sdk/scim/v1/async_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ async def _perform_http_request(
retry_response: Optional[RetryHttpResponse] = None
response_body = ""

if self.logger.level <= logging.DEBUG:
if self.logger.isEnabledFor(logging.DEBUG):
headers_for_logging = {
k: "(redacted)" if k.lower() == "authorization" else v for k, v in headers.items()
}
Expand Down Expand Up @@ -351,8 +351,8 @@ async def _perform_http_request(
response=retry_response,
error=e,
):
if self.logger.level <= logging.DEBUG:
self.logger.info(
if self.logger.isEnabledFor(logging.DEBUG):
self.logger.debug(
f"A retry handler found: {type(handler).__name__} "
f"for {http_verb} {url} - status: {res.status}"
)
Expand All @@ -362,6 +362,7 @@ async def _perform_http_request(
response=retry_response,
error=e,
)
self.logger.info(f"Going to retry the same request: {http_verb} {url}")
break

if retry_state.next_attempt_requested is False:
Expand All @@ -383,8 +384,8 @@ async def _perform_http_request(
response=retry_response,
error=e,
):
if self.logger.level <= logging.DEBUG:
self.logger.info(
if self.logger.isEnabledFor(logging.DEBUG):
self.logger.debug(
f"A retry handler found: {type(handler).__name__} for {http_verb} {url} - {e}"
)
await handler.prepare_for_next_attempt_async(
Expand All @@ -393,6 +394,7 @@ async def _perform_http_request(
response=retry_response,
error=e,
)
self.logger.info(f"Going to retry the same request: {http_verb} {url}")
break

if retry_state.next_attempt_requested is False:
Expand Down
11 changes: 6 additions & 5 deletions slack_sdk/scim/v1/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ def _perform_http_request(
body = json.dumps(body)
headers["Content-Type"] = "application/json;charset=utf-8"

if self.logger.level <= logging.DEBUG:
if self.logger.isEnabledFor(logging.DEBUG):
headers_for_logging = {k: "(redacted)" if k.lower() == "authorization" else v for k, v in headers.items()}
self.logger.debug(f"Sending a request - {http_verb} url: {url}, body: {body}, headers: {headers_for_logging}")

Expand Down Expand Up @@ -342,8 +342,8 @@ def _perform_http_request(
response=retry_response,
error=e,
):
if self.logger.level <= logging.DEBUG:
self.logger.info(
if self.logger.isEnabledFor(logging.DEBUG):
self.logger.debug(
f"A retry handler found: {type(handler).__name__} for {req.method} {req.full_url} - {e}"
)
handler.prepare_for_next_attempt(
Expand All @@ -352,6 +352,7 @@ def _perform_http_request(
response=retry_response,
error=e,
)
self.logger.info(f"Going to retry the same request: {req.method} {req.full_url}")
break

if retry_state.next_attempt_requested is False:
Expand All @@ -370,8 +371,8 @@ def _perform_http_request(
response=None,
error=err,
):
if self.logger.level <= logging.DEBUG:
self.logger.info(
if self.logger.isEnabledFor(logging.DEBUG):
self.logger.debug(
f"A retry handler found: {type(handler).__name__} for {req.method} {req.full_url} - {err}"
)
handler.prepare_for_next_attempt(
Expand Down
2 changes: 1 addition & 1 deletion slack_sdk/scim/v1/internal_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ def _debug_log_response(
logger,
resp: "SCIMResponse", # noqa: F821
) -> None:
if logger.level <= logging.DEBUG:
if logger.isEnabledFor(logging.DEBUG):
logger.debug(
"Received the following response - "
f"status: {resp.status_code}, "
Expand Down
14 changes: 8 additions & 6 deletions slack_sdk/web/async_internal_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ async def _request_with_session(
retry_state.next_attempt_requested = False
retry_response: Optional[RetryHttpResponse] = None

if logger.level <= logging.DEBUG:
if logger.isEnabledFor(logging.DEBUG):

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧪 suggestion (non-blocking): Could the async WebClient get the same not-formatted-when-debug-is-off test? The new guard test only covers the sync client.


def convert_params(values: dict) -> dict:
if not values or not isinstance(values, dict):
Expand Down Expand Up @@ -151,7 +151,7 @@ def convert_params(values: dict) -> dict:
res,
)

if logger.level <= logging.DEBUG:
if logger.isEnabledFor(logging.DEBUG):
body = "(binary)"
if isinstance(data, dict) or isinstance(data, str):
body = data # type: ignore[assignment]
Expand All @@ -175,14 +175,15 @@ def convert_params(values: dict) -> dict:
response=retry_response,
error=error,
):
if logger.level <= logging.DEBUG:
logger.info(f"A retry handler found: {type(handler).__name__} for {http_verb} {api_url}")
if logger.isEnabledFor(logging.DEBUG):
logger.debug(f"A retry handler found: {type(handler).__name__} for {http_verb} {api_url}")
await handler.prepare_for_next_attempt_async(
state=retry_state,
request=retry_request,
response=retry_response,
error=error,
)
logger.info(f"Going to retry the same request: {http_verb} {api_url}")
break

if retry_state.next_attempt_requested is False:
Expand All @@ -202,14 +203,15 @@ def convert_params(values: dict) -> dict:
response=retry_response,
error=e,
):
if logger.level <= logging.DEBUG:
logger.info(f"A retry handler found: {type(handler).__name__} for {http_verb} {api_url} - {e}")
if logger.isEnabledFor(logging.DEBUG):
logger.debug(f"A retry handler found: {type(handler).__name__} for {http_verb} {api_url} - {e}")
await handler.prepare_for_next_attempt_async(
state=retry_state,
request=retry_request,
response=retry_response,
error=e,
)
logger.info(f"Going to retry the same request: {http_verb} {api_url}")
break

if retry_state.next_attempt_requested is False:
Expand Down
Loading
Loading