perf(日志): 降噪优化,将常规成功日志降级为 Debug 级别
- GIN Logger 中间件跳过 /health 和 /setup/status 的请求日志 - UsageCleanup 空闲轮询(no_task)日志降级为 slog.Debug - Scheduler 常规 rebuild ok 日志降级为 slog.Debug - DashboardAggregation 常规聚合完成日志降级为 slog.Debug - TokenRefresh 无刷新活动时周期日志降级为 slog.Debug 生产环境(Info 级别)下自动静默,debug 模式下仍可见。 错误、警告类日志保持原有级别不变。 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -13,9 +13,17 @@ func Logger() gin.HandlerFunc {
|
|||||||
// 开始时间
|
// 开始时间
|
||||||
startTime := time.Now()
|
startTime := time.Now()
|
||||||
|
|
||||||
|
// 请求路径
|
||||||
|
path := c.Request.URL.Path
|
||||||
|
|
||||||
// 处理请求
|
// 处理请求
|
||||||
c.Next()
|
c.Next()
|
||||||
|
|
||||||
|
// 跳过健康检查等高频探针路径的日志
|
||||||
|
if path == "/health" || path == "/setup/status" {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// 结束时间
|
// 结束时间
|
||||||
endTime := time.Now()
|
endTime := time.Now()
|
||||||
|
|
||||||
@@ -25,9 +33,6 @@ func Logger() gin.HandlerFunc {
|
|||||||
// 请求方法
|
// 请求方法
|
||||||
method := c.Request.Method
|
method := c.Request.Method
|
||||||
|
|
||||||
// 请求路径
|
|
||||||
path := c.Request.URL.Path
|
|
||||||
|
|
||||||
// 状态码
|
// 状态码
|
||||||
statusCode := c.Writer.Status()
|
statusCode := c.Writer.Status()
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"log"
|
"log"
|
||||||
|
"log/slog"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -224,11 +225,11 @@ func (s *DashboardAggregationService) runScheduledAggregation() {
|
|||||||
if updateErr != nil {
|
if updateErr != nil {
|
||||||
log.Printf("[DashboardAggregation] 更新水位失败: %v", updateErr)
|
log.Printf("[DashboardAggregation] 更新水位失败: %v", updateErr)
|
||||||
}
|
}
|
||||||
log.Printf("[DashboardAggregation] 聚合完成 (start=%s end=%s duration=%s watermark_updated=%t)",
|
slog.Debug("[DashboardAggregation] 聚合完成",
|
||||||
start.Format(time.RFC3339),
|
"start", start.Format(time.RFC3339),
|
||||||
now.Format(time.RFC3339),
|
"end", now.Format(time.RFC3339),
|
||||||
time.Since(jobStart).String(),
|
"duration", time.Since(jobStart).String(),
|
||||||
updateErr == nil,
|
"watermark_updated", updateErr == nil,
|
||||||
)
|
)
|
||||||
|
|
||||||
s.maybeCleanupRetention(ctx, now)
|
s.maybeCleanupRetention(ctx, now)
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"log"
|
"log"
|
||||||
|
"log/slog"
|
||||||
"strconv"
|
"strconv"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
@@ -451,7 +452,7 @@ func (s *SchedulerSnapshotService) rebuildBucket(ctx context.Context, bucket Sch
|
|||||||
log.Printf("[Scheduler] rebuild cache failed: bucket=%s reason=%s err=%v", bucket.String(), reason, err)
|
log.Printf("[Scheduler] rebuild cache failed: bucket=%s reason=%s err=%v", bucket.String(), reason, err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
log.Printf("[Scheduler] rebuild ok: bucket=%s reason=%s size=%d", bucket.String(), reason, len(accounts))
|
slog.Debug("[Scheduler] rebuild ok", "bucket", bucket.String(), "reason", reason, "size", len(accounts))
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
|
"log/slog"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
@@ -164,9 +165,15 @@ func (s *TokenRefreshService) processRefresh() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 始终打印周期日志,便于跟踪服务运行状态
|
// 无刷新活动时降级为 Debug,有实际刷新活动时保持 Info
|
||||||
log.Printf("[TokenRefresh] Cycle complete: total=%d, oauth=%d, needs_refresh=%d, refreshed=%d, failed=%d",
|
if needsRefresh == 0 && failed == 0 {
|
||||||
totalAccounts, oauthAccounts, needsRefresh, refreshed, failed)
|
slog.Debug("[TokenRefresh] Cycle complete",
|
||||||
|
"total", totalAccounts, "oauth", oauthAccounts,
|
||||||
|
"needs_refresh", needsRefresh, "refreshed", refreshed, "failed", failed)
|
||||||
|
} else {
|
||||||
|
log.Printf("[TokenRefresh] Cycle complete: total=%d, oauth=%d, needs_refresh=%d, refreshed=%d, failed=%d",
|
||||||
|
totalAccounts, oauthAccounts, needsRefresh, refreshed, failed)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// listActiveAccounts 获取所有active状态的账号
|
// listActiveAccounts 获取所有active状态的账号
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
|
"log/slog"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
@@ -174,7 +175,7 @@ func (s *UsageCleanupService) runOnce() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
if task == nil {
|
if task == nil {
|
||||||
log.Printf("[UsageCleanup] run_once done: no_task=true")
|
slog.Debug("[UsageCleanup] run_once done: no_task=true")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user