refactor(log): refactor the whole project
format: {time:YYYY-MM-DD HH:mm:ss} [{level}] | {name} | {message}
{name} is:
- Uvicorn: log from uvicorn server (#228B22)
- Service: log from class of `app.service` (blue)
- Fetcher: log from fetchers (magenta)
- Task: log from `app.tasks` (#FFD700)
- System: log from `system_logger` (red)
- Normal: log from `log(name)` (#FFC1C1)
- Default: the module name of caller
if you are writing services or tasks, you can just call `logger.`, we will pack it with name `Service` or `Task`
if you want to print fetcher logs, system-related logs, or normal logs, use `logger = (fetcher_logger / system_logger / log)(name)`
This commit is contained in:
@@ -180,7 +180,7 @@ This email was sent automatically, please do not reply.
|
||||
return True
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"[Email Verification] Failed to enqueue email: {e}")
|
||||
logger.error(f"Failed to enqueue email: {e}")
|
||||
return False
|
||||
|
||||
@staticmethod
|
||||
@@ -237,7 +237,7 @@ This email was sent automatically, please do not reply.
|
||||
str(verification.id) if verification.id else "0",
|
||||
)
|
||||
|
||||
logger.info(f"[Email Verification] Created verification code for user {user_id}: {code}")
|
||||
logger.info(f"Created verification code for user {user_id}: {code}")
|
||||
return verification, code
|
||||
|
||||
@staticmethod
|
||||
@@ -254,11 +254,11 @@ This email was sent automatically, please do not reply.
|
||||
try:
|
||||
# 检查是否启用邮件验证功能
|
||||
if not settings.enable_email_verification:
|
||||
logger.debug(f"[Email Verification] Email verification is disabled, skipping for user {user_id}")
|
||||
logger.debug(f"Email verification is disabled, skipping for user {user_id}")
|
||||
return True # 返回成功,但不执行验证流程
|
||||
|
||||
# 检测客户端信息
|
||||
logger.info(f"[Email Verification] Detected client for user {user_id}: {user_agent}")
|
||||
logger.info(f"Detected client for user {user_id}: {user_agent}")
|
||||
|
||||
# 创建验证记录
|
||||
(
|
||||
@@ -272,16 +272,14 @@ This email was sent automatically, please do not reply.
|
||||
success = await EmailVerificationService.send_verification_email_via_queue(email, code, username, user_id)
|
||||
|
||||
if success:
|
||||
logger.info(
|
||||
f"[Email Verification] Successfully enqueued verification email to {email} (user: {username})"
|
||||
)
|
||||
logger.info(f"Successfully enqueued verification email to {email} (user: {username})")
|
||||
return True
|
||||
else:
|
||||
logger.error(f"[Email Verification] Failed to enqueue verification email: {email} (user: {username})")
|
||||
logger.error(f"Failed to enqueue verification email: {email} (user: {username})")
|
||||
return False
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"[Email Verification] Exception during sending verification email: {e}")
|
||||
logger.error(f"Exception during sending verification email: {e}")
|
||||
return False
|
||||
|
||||
@staticmethod
|
||||
@@ -299,7 +297,7 @@ This email was sent automatically, please do not reply.
|
||||
try:
|
||||
# 检查是否启用邮件验证功能
|
||||
if not settings.enable_email_verification:
|
||||
logger.debug(f"[Email Verification] Email verification is disabled, auto-approving for user {user_id}")
|
||||
logger.debug(f"Email verification is disabled, auto-approving for user {user_id}")
|
||||
return True, "验证成功(邮件验证功能已禁用)"
|
||||
|
||||
# 先从 Redis 检查
|
||||
@@ -331,11 +329,11 @@ This email was sent automatically, please do not reply.
|
||||
# 删除 Redis 记录
|
||||
await redis.delete(f"email_verification:{user_id}:{code}")
|
||||
|
||||
logger.info(f"[Email Verification] User {user_id} verification code verified successfully")
|
||||
logger.info(f"User {user_id} verification code verified successfully")
|
||||
return True, "验证成功"
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"[Email Verification] Exception during verification code validation: {e}")
|
||||
logger.error(f"Exception during verification code validation: {e}")
|
||||
return False, "验证过程中发生错误"
|
||||
|
||||
@staticmethod
|
||||
@@ -354,7 +352,7 @@ This email was sent automatically, please do not reply.
|
||||
_ = user_agent
|
||||
# 检查是否启用邮件验证功能
|
||||
if not settings.enable_email_verification:
|
||||
logger.debug(f"[Email Verification] Email verification is disabled, skipping resend for user {user_id}")
|
||||
logger.debug(f"Email verification is disabled, skipping resend for user {user_id}")
|
||||
return True, "验证码已发送(邮件验证功能已禁用)"
|
||||
|
||||
# 检查重发频率限制(60秒内只能发送一次)
|
||||
@@ -376,7 +374,7 @@ This email was sent automatically, please do not reply.
|
||||
return False, "重新发送失败,请稍后再试"
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"[Email Verification] Exception during resending verification code: {e}")
|
||||
logger.error(f"Exception during resending verification code: {e}")
|
||||
return False, "重新发送过程中发生错误"
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user