From 8c5d87a5d2e911e99536edc33535a123e54c2697 Mon Sep 17 00:00:00 2001 From: chan Date: Tue, 20 Jan 2026 10:56:15 +0900 Subject: [PATCH] 200 log x --- backend/cmd/server/main.go | 26 ++++++++++++++++--- .../internal/repository/clickhouse_repo.go | 2 +- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/backend/cmd/server/main.go b/backend/cmd/server/main.go index f31f80d5..522852b1 100644 --- a/backend/cmd/server/main.go +++ b/backend/cmd/server/main.go @@ -3,8 +3,9 @@ package main import ( "log/slog" "os" - "strconv" - "time" + "strings" + "strconv" + "time" "github.com/bwmarrin/snowflake" @@ -99,6 +100,13 @@ func main() { // Log after request latency := time.Since(start) + status := c.Response().StatusCode() + path := c.Path() + + // Skip logging for all successful requests (status < 400) + if status < 400 { + return err + } msg := "http_request" if err != nil { @@ -106,9 +114,9 @@ func main() { } slog.Info(msg, - "status", c.Response().StatusCode(), + "status", status, "method", c.Method(), - "path", c.Path(), + "path", path, "latency", latency.String(), "ip", c.IP(), "req_id", c.GetRespHeader(fiber.HeaderXRequestID), @@ -241,6 +249,16 @@ func main() { level = slog.LevelInfo } + // Filter out noisy client navigation logs + if level == slog.LevelInfo { + msg := strings.ToLower(req.Message) + if strings.Contains(msg, "navigating to") || + strings.Contains(msg, "going to") || + strings.Contains(msg, "redirecting to") { + return c.SendStatus(fiber.StatusOK) + } + } + slog.Log(c.Context(), level, req.Message, attrs...) return c.SendStatus(fiber.StatusOK) }) diff --git a/backend/internal/repository/clickhouse_repo.go b/backend/internal/repository/clickhouse_repo.go index 278a9d9d..4b3fe03d 100644 --- a/backend/internal/repository/clickhouse_repo.go +++ b/backend/internal/repository/clickhouse_repo.go @@ -23,7 +23,7 @@ func NewClickHouseRepository(host string, port int, user, password, db string) ( Username: user, Password: password, }, - Debug: true, + Debug: false, }) if err != nil {