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

@@ -80,16 +80,10 @@ func (h *PostHandler) GetByID(c *gin.Context) {
// 注意:不再自动增加浏览量,浏览量通过 RecordView 端点单独记录
// 获取当前用户ID用于判断点赞和收藏状态
fmt.Printf("[DEBUG] GetByID - postID: %s, currentUserID: %s\n", id, currentUserID)
var isLiked, isFavorited bool
if currentUserID != "" {
isLiked = h.postService.IsLiked(c.Request.Context(), id, currentUserID)
isFavorited = h.postService.IsFavorited(c.Request.Context(), id, currentUserID)
fmt.Printf("[DEBUG] GetByID - isLiked: %v, isFavorited: %v\n", isLiked, isFavorited)
} else {
fmt.Printf("[DEBUG] GetByID - user not logged in, isLiked: false, isFavorited: false\n")
}
// 如果有当前用户,检查与帖子作者的相互关注状态
@@ -142,7 +136,7 @@ func (h *PostHandler) RecordView(c *gin.Context) {
// 增加浏览量
if err := h.postService.IncrementViews(c.Request.Context(), id, userID); err != nil {
fmt.Printf("[DEBUG] Failed to increment views for post %s: %v\n", id, err)
fmt.Printf("[ERROR] Failed to increment views for post %s: %v\n", id, err)
response.InternalServerError(c, "failed to record view")
return
}
@@ -192,8 +186,6 @@ func (h *PostHandler) List(c *gin.Context) {
return
}
fmt.Printf("[DEBUG] List - tab: %s, currentUserID: %s, posts count: %d\n", tab, currentUserID, len(posts))
isLikedMap := make(map[string]bool)
isFavoritedMap := make(map[string]bool)
if currentUserID != "" {
@@ -202,10 +194,7 @@ func (h *PostHandler) List(c *gin.Context) {
isFavorited := h.postService.IsFavorited(c.Request.Context(), post.ID, currentUserID)
isLikedMap[post.ID] = isLiked
isFavoritedMap[post.ID] = isFavorited
fmt.Printf("[DEBUG] List - postID: %s, isLiked: %v, isFavorited: %v\n", post.ID, isLiked, isFavorited)
}
} else {
fmt.Printf("[DEBUG] List - user not logged in\n")
}
// 转换为响应结构
@@ -308,7 +297,6 @@ func (h *PostHandler) Like(c *gin.Context) {
}
id := c.Param("id")
fmt.Printf("[DEBUG] Like - postID: %s, userID: %s\n", id, userID)
err := h.postService.Like(c.Request.Context(), id, userID)
if err != nil {
@@ -325,7 +313,6 @@ func (h *PostHandler) Like(c *gin.Context) {
isLiked := h.postService.IsLiked(c.Request.Context(), id, userID)
isFavorited := h.postService.IsFavorited(c.Request.Context(), id, userID)
fmt.Printf("[DEBUG] Like - postID: %s, isLiked: %v, isFavorited: %v\n", id, isLiked, isFavorited)
response.Success(c, dto.ConvertPostToResponse(post, isLiked, isFavorited))
}
@@ -339,7 +326,6 @@ func (h *PostHandler) Unlike(c *gin.Context) {
}
id := c.Param("id")
fmt.Printf("[DEBUG] Unlike - postID: %s, userID: %s\n", id, userID)
err := h.postService.Unlike(c.Request.Context(), id, userID)
if err != nil {
@@ -356,7 +342,6 @@ func (h *PostHandler) Unlike(c *gin.Context) {
isLiked := h.postService.IsLiked(c.Request.Context(), id, userID)
isFavorited := h.postService.IsFavorited(c.Request.Context(), id, userID)
fmt.Printf("[DEBUG] Unlike - postID: %s, isLiked: %v, isFavorited: %v\n", id, isLiked, isFavorited)
response.Success(c, dto.ConvertPostToResponse(post, isLiked, isFavorited))
}
@@ -370,7 +355,6 @@ func (h *PostHandler) Favorite(c *gin.Context) {
}
id := c.Param("id")
fmt.Printf("[DEBUG] Favorite - postID: %s, userID: %s\n", id, userID)
err := h.postService.Favorite(c.Request.Context(), id, userID)
if err != nil {
@@ -387,7 +371,6 @@ func (h *PostHandler) Favorite(c *gin.Context) {
isLiked := h.postService.IsLiked(c.Request.Context(), id, userID)
isFavorited := h.postService.IsFavorited(c.Request.Context(), id, userID)
fmt.Printf("[DEBUG] Favorite - postID: %s, isLiked: %v, isFavorited: %v\n", id, isLiked, isFavorited)
response.Success(c, dto.ConvertPostToResponse(post, isLiked, isFavorited))
}
@@ -401,7 +384,6 @@ func (h *PostHandler) Unfavorite(c *gin.Context) {
}
id := c.Param("id")
fmt.Printf("[DEBUG] Unfavorite - postID: %s, userID: %s\n", id, userID)
err := h.postService.Unfavorite(c.Request.Context(), id, userID)
if err != nil {
@@ -418,7 +400,6 @@ func (h *PostHandler) Unfavorite(c *gin.Context) {
isLiked := h.postService.IsLiked(c.Request.Context(), id, userID)
isFavorited := h.postService.IsFavorited(c.Request.Context(), id, userID)
fmt.Printf("[DEBUG] Unfavorite - postID: %s, isLiked: %v, isFavorited: %v\n", id, isLiked, isFavorited)
response.Success(c, dto.ConvertPostToResponse(post, isLiked, isFavorited))
}