Refactor: use logger = logging.getLogger(__name__) in logging (#24515)

Co-authored-by: Yongtao Huang <99629139+hyongtao-db@users.noreply.github.com>
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Co-authored-by: crazywoola <100913391+crazywoola@users.noreply.github.com>
This commit is contained in:
Yongtao Huang
2025-08-26 18:10:31 +08:00
committed by GitHub
parent 8af2ae973f
commit fa753239ad
102 changed files with 565 additions and 401 deletions

View File

@@ -27,6 +27,8 @@ if TYPE_CHECKING:
from models.account import Account
from models.model import EndUser
logger = logging.getLogger(__name__)
def extract_tenant_id(user: Union["Account", "EndUser"]) -> str | None:
"""
@@ -321,7 +323,7 @@ class TokenManager:
key = cls._get_token_key(token, token_type)
token_data_json = redis_client.get(key)
if token_data_json is None:
logging.warning("%s token %s not found with key %s", token_type, token, key)
logger.warning("%s token %s not found with key %s", token_type, token, key)
return None
token_data: Optional[dict[str, Any]] = json.loads(token_data_json)
return token_data

View File

@@ -4,6 +4,8 @@ import sendgrid # type: ignore
from python_http_client.exceptions import ForbiddenError, UnauthorizedError
from sendgrid.helpers.mail import Content, Email, Mail, To # type: ignore
logger = logging.getLogger(__name__)
class SendGridClient:
def __init__(self, sendgrid_api_key: str, _from: str):
@@ -11,7 +13,7 @@ class SendGridClient:
self._from = _from
def send(self, mail: dict):
logging.debug("Sending email with SendGrid")
logger.debug("Sending email with SendGrid")
try:
_to = mail["to"]
@@ -27,19 +29,19 @@ class SendGridClient:
mail = Mail(from_email, to_email, subject, content)
mail_json = mail.get() # type: ignore
response = sg.client.mail.send.post(request_body=mail_json)
logging.debug(response.status_code)
logging.debug(response.body)
logging.debug(response.headers)
logger.debug(response.status_code)
logger.debug(response.body)
logger.debug(response.headers)
except TimeoutError as e:
logging.exception("SendGridClient Timeout occurred while sending email")
logger.exception("SendGridClient Timeout occurred while sending email")
raise
except (UnauthorizedError, ForbiddenError) as e:
logging.exception(
logger.exception(
"SendGridClient Authentication failed. "
"Verify that your credentials and the 'from' email address are correct"
)
raise
except Exception as e:
logging.exception("SendGridClient Unexpected error occurred while sending email to %s", _to)
logger.exception("SendGridClient Unexpected error occurred while sending email to %s", _to)
raise

View File

@@ -3,6 +3,8 @@ import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
logger = logging.getLogger(__name__)
class SMTPClient:
def __init__(
@@ -44,13 +46,13 @@ class SMTPClient:
smtp.sendmail(self._from, mail["to"], msg.as_string())
except smtplib.SMTPException as e:
logging.exception("SMTP error occurred")
logger.exception("SMTP error occurred")
raise
except TimeoutError as e:
logging.exception("Timeout occurred while sending email")
logger.exception("Timeout occurred while sending email")
raise
except Exception as e:
logging.exception("Unexpected error occurred while sending email to %s", mail["to"])
logger.exception("Unexpected error occurred while sending email to %s", mail["to"])
raise
finally:
if smtp: