Clean backend debug logging and standardize error reporting.

This removes verbose trace output in handlers/services and keeps only actionable error-level logs.
This commit is contained in:
2026-03-09 22:18:53 +08:00
parent 4d8f2ec997
commit 4c0177149a
13 changed files with 8 additions and 163 deletions

View File

@@ -165,15 +165,11 @@ func (s *systemMessageServiceImpl) SendReplyNotification(ctx context.Context, us
// SendFollowNotification 发送关注通知
func (s *systemMessageServiceImpl) SendFollowNotification(ctx context.Context, userID string, operatorID string) error {
fmt.Printf("[DEBUG] SendFollowNotification: userID=%s, operatorID=%s\n", userID, operatorID)
// 获取操作者信息
actorName, avatarURL, err := s.getActorInfo(ctx, operatorID)
if err != nil {
fmt.Printf("[DEBUG] SendFollowNotification: getActorInfo error: %v\n", err)
return err
}
fmt.Printf("[DEBUG] SendFollowNotification: actorName=%s, avatarURL=%s\n", actorName, avatarURL)
extraData := &model.SystemNotificationExtra{
ActorIDStr: operatorID,
@@ -193,16 +189,8 @@ func (s *systemMessageServiceImpl) SendFollowNotification(ctx context.Context, u
return fmt.Errorf("failed to create follow notification: %w", err)
}
fmt.Printf("[DEBUG] SendFollowNotification: notification created, ID=%d, Content=%s\n", notification.ID, notification.Content)
// 推送通知
pushErr := s.pushService.PushSystemNotification(ctx, userID, notification)
if pushErr != nil {
fmt.Printf("[DEBUG] SendFollowNotification: PushSystemNotification error: %v\n", pushErr)
} else {
fmt.Printf("[DEBUG] SendFollowNotification: PushSystemNotification success\n")
}
return pushErr
return s.pushService.PushSystemNotification(ctx, userID, notification)
}
// SendFavoriteNotification 发送收藏通知
@@ -387,12 +375,9 @@ func (s *systemMessageServiceImpl) SendBroadcastAnnouncement(ctx context.Context
// createNotification 创建系统通知(存储到独立表)
func (s *systemMessageServiceImpl) createNotification(ctx context.Context, userID string, notifyType model.SystemNotificationType, content string, extraData *model.SystemNotificationExtra) (*model.SystemNotification, error) {
fmt.Printf("[DEBUG] createNotification: userID=%s, notifyType=%s\n", userID, notifyType)
// 生成雪花算法ID
id, err := utils.GetSnowflake().GenerateID()
if err != nil {
fmt.Printf("[DEBUG] createNotification: failed to generate ID: %v\n", err)
return nil, fmt.Errorf("failed to generate notification ID: %w", err)
}
@@ -405,18 +390,14 @@ func (s *systemMessageServiceImpl) createNotification(ctx context.Context, userI
IsRead: false,
}
fmt.Printf("[DEBUG] createNotification: notification created with ID=%d, ReceiverID=%s\n", id, userID)
// 保存通知到数据库
if err := s.notifyRepo.Create(notification); err != nil {
fmt.Printf("[DEBUG] createNotification: failed to save notification: %v\n", err)
return nil, fmt.Errorf("failed to save notification: %w", err)
}
// 失效系统消息未读数缓存
cache.InvalidateUnreadSystem(s.cache, userID)
fmt.Printf("[DEBUG] createNotification: notification saved successfully, ID=%d\n", notification.ID)
return notification, nil
}
@@ -426,7 +407,6 @@ func (s *systemMessageServiceImpl) getActorInfo(ctx context.Context, operatorID
if s.userRepo != nil {
user, err := s.userRepo.GetByID(operatorID)
if err != nil {
fmt.Printf("[DEBUG] getActorInfo: failed to get user %s: %v\n", operatorID, err)
return "用户", utils.GenerateDefaultAvatarURL("用户"), nil // 返回默认值,不阻断流程
}
avatar := utils.GetAvatarOrDefault(user.Username, user.Nickname, user.Avatar)