From 7271fb68aa4c897982f96e46dc0a6453e84ac2c1 Mon Sep 17 00:00:00 2001 From: Anders Kaseorg Date: Sat, 2 May 2020 11:57:12 -0700 Subject: [PATCH] logging: Pass format arguments to unconventionally-named loggers too. Signed-off-by: Anders Kaseorg --- corporate/lib/stripe.py | 15 ++++++++++----- corporate/views.py | 9 +++++---- zproject/backends.py | 2 +- 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/corporate/lib/stripe.py b/corporate/lib/stripe.py index 20355e0479..84c0f83faf 100644 --- a/corporate/lib/stripe.py +++ b/corporate/lib/stripe.py @@ -153,8 +153,10 @@ def catch_stripe_errors(func: CallableT) -> CallableT: # https://stripe.com/docs/error-codes gives a more detailed set of error codes except stripe.error.StripeError as e: err = e.json_body.get('error', {}) - billing_logger.error("Stripe error: %s %s %s %s" % ( - e.http_status, err.get('type'), err.get('code'), err.get('param'))) + billing_logger.error( + "Stripe error: %s %s %s %s", + e.http_status, err.get('type'), err.get('code'), err.get('param'), + ) if isinstance(e, stripe.error.CardError): # TODO: Look into i18n for this raise StripeCardError('card error', err.get('message')) @@ -285,7 +287,8 @@ def process_initial_upgrade(user: UserProfile, licenses: int, automanage_license # at exactly the same time. Doesn't fully resolve the race condition, but having # a check here reduces the likelihood. billing_logger.warning( - "Customer {} trying to upgrade, but has an active subscription".format(customer)) + "Customer %s trying to upgrade, but has an active subscription", customer, + ) raise BillingError('subscribing with existing subscription', BillingError.TRY_RELOADING) billing_cycle_anchor, next_invoice_date, period_end, price_per_license = compute_plan_parameters( @@ -476,8 +479,10 @@ def get_discount_for_realm(realm: Realm) -> Optional[Decimal]: def do_change_plan_status(plan: CustomerPlan, status: int) -> None: plan.status = status plan.save(update_fields=['status']) - billing_logger.info('Change plan status: Customer.id: %s, CustomerPlan.id: %s, status: %s' % ( - plan.customer.id, plan.id, status)) + billing_logger.info( + 'Change plan status: Customer.id: %s, CustomerPlan.id: %s, status: %s', + plan.customer.id, plan.id, status, + ) def process_downgrade(plan: CustomerPlan) -> None: from zerver.lib.actions import do_change_plan_type diff --git a/corporate/views.py b/corporate/views.py index 95459a3d13..f929205d7f 100644 --- a/corporate/views.py +++ b/corporate/views.py @@ -99,10 +99,11 @@ def upgrade(request: HttpRequest, user: UserProfile, except BillingError as e: if not settings.TEST_SUITE: # nocoverage billing_logger.warning( - ("BillingError during upgrade: %s. user=%s, realm=%s (%s), billing_modality=%s, " - "schedule=%s, license_management=%s, licenses=%s, has stripe_token: %s") - % (e.description, user.id, user.realm.id, user.realm.string_id, billing_modality, - schedule, license_management, licenses, stripe_token is not None)) + "BillingError during upgrade: %s. user=%s, realm=%s (%s), billing_modality=%s, " + "schedule=%s, license_management=%s, licenses=%s, has stripe_token: %s", + e.description, user.id, user.realm.id, user.realm.string_id, billing_modality, + schedule, license_management, licenses, stripe_token is not None, + ) return json_error(e.message, data={'error_description': e.description}) except Exception as e: billing_logger.exception("Uncaught exception in billing: %s" % (e,)) diff --git a/zproject/backends.py b/zproject/backends.py index 62376c58bc..b2fc1a2e5b 100644 --- a/zproject/backends.py +++ b/zproject/backends.py @@ -618,7 +618,7 @@ class ZulipLDAPAuthBackend(ZulipLDAPAuthBackendBase): # django-auth-ldap authenticate(). username = self.django_to_ldap_username(username) except ZulipLDAPExceptionNoMatchingLDAPUser as e: - ldap_logger.debug("{}: {}".format(self.__class__.__name__, e)) + ldap_logger.debug("%s: %s", self.__class__.__name__, e) if return_data is not None: return_data['no_matching_ldap_user'] = True return None