forked from baron/baron-sso
200 log x
This commit is contained in:
@@ -3,6 +3,7 @@ package main
|
|||||||
import (
|
import (
|
||||||
"log/slog"
|
"log/slog"
|
||||||
"os"
|
"os"
|
||||||
|
"strings"
|
||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -99,6 +100,13 @@ func main() {
|
|||||||
|
|
||||||
// Log after request
|
// Log after request
|
||||||
latency := time.Since(start)
|
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"
|
msg := "http_request"
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -106,9 +114,9 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
slog.Info(msg,
|
slog.Info(msg,
|
||||||
"status", c.Response().StatusCode(),
|
"status", status,
|
||||||
"method", c.Method(),
|
"method", c.Method(),
|
||||||
"path", c.Path(),
|
"path", path,
|
||||||
"latency", latency.String(),
|
"latency", latency.String(),
|
||||||
"ip", c.IP(),
|
"ip", c.IP(),
|
||||||
"req_id", c.GetRespHeader(fiber.HeaderXRequestID),
|
"req_id", c.GetRespHeader(fiber.HeaderXRequestID),
|
||||||
@@ -241,6 +249,16 @@ func main() {
|
|||||||
level = slog.LevelInfo
|
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...)
|
slog.Log(c.Context(), level, req.Message, attrs...)
|
||||||
return c.SendStatus(fiber.StatusOK)
|
return c.SendStatus(fiber.StatusOK)
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ func NewClickHouseRepository(host string, port int, user, password, db string) (
|
|||||||
Username: user,
|
Username: user,
|
||||||
Password: password,
|
Password: password,
|
||||||
},
|
},
|
||||||
Debug: true,
|
Debug: false,
|
||||||
})
|
})
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user