重构日志与可观测性体系

新增单行文本编码器与结构化 GORM 日志,统一错误记录与请求日志策略,收紧日志文件权限并修复按天切分与压缩,支付回调参数脱敏,生产强制阿里云短信,RequestID 校验防注入,日志文案中文化。
This commit is contained in:
yml2213
2026-07-29 16:19:35 +08:00
parent e75f1a8519
commit 88d74aca7d
64 changed files with 896 additions and 277 deletions
+1
View File
@@ -212,6 +212,7 @@ func (h *Handler) ResetPassword(c *gin.Context) {
}
func writeAuthError(c *gin.Context, err error) {
response.RecordError(c, err)
switch {
case errors.Is(err, ErrDependencyUnavailable):
response.ServiceUnavailable(c, "数据库或 Redis 未连接")
+10 -1
View File
@@ -11,6 +11,7 @@ import (
"hfb_sys/backend/internal/captcha"
smsprovider "hfb_sys/backend/internal/integrations/sms"
"hfb_sys/backend/internal/logging"
"hfb_sys/backend/internal/model"
"github.com/redis/go-redis/v9"
@@ -120,7 +121,15 @@ func (s *Service) SendSMSCode(ctx context.Context, phone string, captchaID strin
}
if err := s.sms.SendLoginCode(ctx, phone, code); err != nil {
if s.log != nil {
s.log.Warn("sms login code send failed", zap.String("phone", PublicPhone(phone)), zap.Error(err))
fields := []zap.Field{
zap.String("module", "auth"),
zap.String("phone", PublicPhone(phone)),
zap.Error(err),
}
if requestID := logging.RequestIDFromContext(ctx); requestID != "" {
fields = append(fields, zap.String("request_id", requestID))
}
s.log.Warn("短信验证码发送失败", fields...)
}
if smsprovider.IsProviderRateLimited(err) {
pipe := s.redis.TxPipeline()