优化日志系统
This commit is contained in:
+5
-6
@@ -4,7 +4,6 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
@@ -34,13 +33,13 @@ func (s *appState) handleProducts(w http.ResponseWriter, r *http.Request) {
|
||||
if refresh {
|
||||
products, err := s.client.Products()
|
||||
if err != nil {
|
||||
log.Printf("商品刷新失败: %v", err)
|
||||
logEvent("商品", "error", "商品刷新失败: %v", err)
|
||||
writeError(w, http.StatusBadGateway, err)
|
||||
return
|
||||
}
|
||||
fetchedAt := time.Now()
|
||||
s.setProducts(products, fetchedAt)
|
||||
log.Printf("商品刷新完成: %d 个,刷新时间=%s", len(products), fetchedAt.In(cst).Format("15:04:05.000"))
|
||||
logEvent("商品", "success", "商品刷新完成: %d 个,刷新时间=%s", len(products), fetchedAt.In(cst).Format("15:04:05.000"))
|
||||
writeJSON(w, s.productPayload("live"))
|
||||
return
|
||||
}
|
||||
@@ -51,13 +50,13 @@ func (s *appState) handleProducts(w http.ResponseWriter, r *http.Request) {
|
||||
func (s *appState) handleLoadProducts(w http.ResponseWriter, _ *http.Request) {
|
||||
products, err := s.client.Products()
|
||||
if err != nil {
|
||||
log.Printf("商品刷新失败: %v", err)
|
||||
logEvent("商品", "error", "商品刷新失败: %v", err)
|
||||
writeError(w, http.StatusBadGateway, err)
|
||||
return
|
||||
}
|
||||
fetchedAt := time.Now()
|
||||
s.setProducts(products, fetchedAt)
|
||||
log.Printf("商品刷新完成: %d 个,刷新时间=%s", len(products), fetchedAt.In(cst).Format("15:04:05.000"))
|
||||
logEvent("商品", "success", "商品刷新完成: %d 个,刷新时间=%s", len(products), fetchedAt.In(cst).Format("15:04:05.000"))
|
||||
writeJSON(w, s.productPayload("live"))
|
||||
}
|
||||
|
||||
@@ -159,7 +158,7 @@ func (s *appState) handleTime(w http.ResponseWriter, _ *http.Request) {
|
||||
source := "currentTime"
|
||||
if err != nil {
|
||||
source = "localFallback"
|
||||
log.Printf("时间接口降级: %v", err)
|
||||
logEvent("时间", "warn", "时间接口降级: %v", err)
|
||||
}
|
||||
writeJSON(w, map[string]any{
|
||||
"serverTime": serverTime.In(cst).Format("2006-01-02 15:04:05.000"),
|
||||
|
||||
Reference in New Issue
Block a user