forked from baron/baron-sso
200 log x
This commit is contained in:
@@ -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)
|
||||
})
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user