From b45484573e492dc5c424d7788c8d160624e53228 Mon Sep 17 00:00:00 2001 From: Anders Kaseorg Date: Fri, 7 Oct 2022 22:34:49 -0700 Subject: [PATCH] python: Use format string for logging str(obj). Signed-off-by: Anders Kaseorg --- zerver/lib/fix_unreads.py | 2 +- zerver/lib/send_email.py | 4 +--- zerver/worker/queue_processors.py | 2 +- zproject/backends.py | 4 ++-- 4 files changed, 5 insertions(+), 7 deletions(-) diff --git a/zerver/lib/fix_unreads.py b/zerver/lib/fix_unreads.py index 83576fe48b..24b283ea66 100644 --- a/zerver/lib/fix_unreads.py +++ b/zerver/lib/fix_unreads.py @@ -94,7 +94,7 @@ def fix_unsubscribed(cursor: CursorWrapper, user_profile: UserProfile) -> None: rows = cursor.fetchall() for row in rows: recipient_ids.append(row[0]) - logger.info(str(recipient_ids)) + logger.info("%s", recipient_ids) get_timing( "get recipients", diff --git a/zerver/lib/send_email.py b/zerver/lib/send_email.py index ab4209e3cc..ed067594d5 100644 --- a/zerver/lib/send_email.py +++ b/zerver/lib/send_email.py @@ -289,9 +289,7 @@ def send_email( ) raise EmailNotDeliveredException except smtplib.SMTPException as e: - logger.exception( - "Error sending %s email to %s: %s", template, mail.to, str(e), stack_info=True - ) + logger.exception("Error sending %s email to %s: %s", template, mail.to, e, stack_info=True) raise EmailNotDeliveredException diff --git a/zerver/worker/queue_processors.py b/zerver/worker/queue_processors.py index 5131de2792..9b0caa72e5 100644 --- a/zerver/worker/queue_processors.py +++ b/zerver/worker/queue_processors.py @@ -958,7 +958,7 @@ class EmbeddedBotWorker(QueueProcessingWorker): bot_handler=self.get_bot_api_client(user_profile), ) except EmbeddedBotQuitException as e: - logging.warning(str(e)) + logging.warning("%s", e) @assign_queue("deferred_work") diff --git a/zproject/backends.py b/zproject/backends.py index 6e9827b53c..f473a7a7c5 100644 --- a/zproject/backends.py +++ b/zproject/backends.py @@ -1822,12 +1822,12 @@ class SocialAuthMixin(ZulipAuthMixin, ExternalAuthMethod, BaseAuth): # the flow or the IdP is unreliable and returns a bad http response), # don't throw a 500, just send them back to the # login page and record the event at the info log level. - self.logger.info("%s: %s", type(e).__name__, str(e)) + self.logger.info("%s: %s", type(e).__name__, e) return None except SocialAuthBaseException as e: # Other python-social-auth exceptions are likely # interesting enough that we should log a warning. - self.logger.warning(str(e)) + self.logger.warning("%s", e) return None def should_auto_signup(self) -> bool: