1
0
forked from baron/baron-sso

200 log x

This commit is contained in:
2026-01-20 10:56:15 +09:00
parent 16552dac54
commit 8c5d87a5d2
2 changed files with 23 additions and 5 deletions

View File

@@ -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)
})

View File

@@ -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 {