Skip to content

Modern Docker Management, Designed for Everyone

fix: remove file line from db debug logs

Kyle Mendellfbe204c5ce91
diff --git a/backend/internal/bootstrap/logger_bootstrap.go b/backend/internal/bootstrap/logger_bootstrap.go
index 4793e9bab..7aa71cea4 100644
--- a/backend/internal/bootstrap/logger_bootstrap.go
+++ b/backend/internal/bootstrap/logger_bootstrap.go
@@ -21,6 +21,11 @@ type timeFilterHandler struct {
handler slog.Handler
}
+type attrFilterHandler struct {
+ handler slog.Handler
+ dropKeys map[string]struct{}
+}
+
func (h *timeFilterHandler) Enabled(ctx context.Context, level slog.Level) bool {
return h.handler.Enabled(ctx, level)
}
@@ -83,6 +88,34 @@ func (h *timeFilterHandler) WithGroup(name string) slog.Handler {
return &timeFilterHandler{handler: h.handler.WithGroup(name)}
}
+func (h *attrFilterHandler) Enabled(ctx context.Context, level slog.Level) bool {
+ return h.handler.Enabled(ctx, level)
+}
+
+func (h *attrFilterHandler) Handle(ctx context.Context, r slog.Record) error {
+ var filteredAttrs []slog.Attr
+ r.Attrs(func(a slog.Attr) bool {
+ if _, drop := h.dropKeys[a.Key]; drop {
+ return true
+ }
+ filteredAttrs = append(filteredAttrs, a)
+ return true
+ })
+
+ newRecord := slog.NewRecord(r.Time, r.Level, r.Message, r.PC)
+ newRecord.AddAttrs(filteredAttrs...)
+
+ return h.handler.Handle(ctx, newRecord)
+}
+
+func (h *attrFilterHandler) WithAttrs(attrs []slog.Attr) slog.Handler {
+ return &attrFilterHandler{handler: h.handler.WithAttrs(attrs), dropKeys: h.dropKeys}
+}
+
+func (h *attrFilterHandler) WithGroup(name string) slog.Handler {
+ return &attrFilterHandler{handler: h.handler.WithGroup(name), dropKeys: h.dropKeys}
+}
+
func SetupGinLogger(cfg *config.Config) {
var lvl slog.Level
switch strings.ToLower(cfg.LogLevel) {
@@ -118,8 +151,13 @@ func SetupGinLogger(cfg *config.Config) {
func BuildGormLogger(cfg *config.Config) logger.Interface {
lvl := strings.ToLower(cfg.LogLevel)
+ filteredHandler := &attrFilterHandler{
+ handler: slog.Default().Handler(),
+ dropKeys: map[string]struct{}{slogGorm.SourceField: {}},
+ }
+
opts := []slogGorm.Option{
- slogGorm.WithHandler(slog.Default().Handler()),
+ slogGorm.WithHandler(filteredHandler),
slogGorm.WithSlowThreshold(200 * time.Millisecond),
}
diff --git a/go.work.sum b/go.work.sum
index 5d7f408fd..dd911dfed 100644
--- a/go.work.sum
+++ b/go.work.sum
@@ -254,6 +254,7 @@ github.com/godbus/dbus/v5 v5.1.0 h1:4KLkAxT3aOY8Li4FRJe/KvhoNFFxo0m6fNuFUO8QJUk=
github.com/godbus/dbus/v5 v5.1.0/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
github.com/gofiber/fiber/v2 v2.52.7 h1:6xJpE4sSqErvMiEZo9ZpJLRSVcpkNBvioeqAHKwhTZY=
github.com/gofiber/fiber/v2 v2.52.7/go.mod h1:YEcBbO/FB+5M1IZNBP9FO3J9281zgPAreiI1oqg8nDw=
+github.com/gofiber/fiber/v2 v2.52.9/go.mod h1:YEcBbO/FB+5M1IZNBP9FO3J9281zgPAreiI1oqg8nDw=
github.com/golang-jwt/jwt/v4 v4.5.2 h1:YtQM7lnr8iZ+j5q71MGKkNw9Mn7AjHM68uc9g5fXeUI=
github.com/golang-jwt/jwt/v4 v4.5.2/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0=
github.com/golang-sql/civil v0.0.0-20190719163853-cb61b32ac6fe h1:lXe2qZdvpiX5WZkZR4hgp4KJVfY3nMkvmwbVkpv1rVY=