Skip to content

Commit

Permalink
fix: retain level when using WithAttrs/WithGroup
Browse files Browse the repository at this point in the history
Because these methods were not persisting the level in the GoKitHandler
through to the new handler, the level would be unset in later log calls,
resulting in the level dropping back to info by default.

Signed-off-by: TJ Hoplock <[email protected]>
  • Loading branch information
tjhop committed Nov 22, 2024
1 parent b8eba7d commit 705216f
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,12 @@ func (h *GoKitHandler) WithAttrs(attrs []slog.Attr) slog.Handler {
pairs = append(h.preformatted, pairs...)
}

return &GoKitHandler{logger: h.logger, preformatted: pairs, group: h.group}
return &GoKitHandler{
logger: h.logger,
level: h.level,
preformatted: pairs,
group: h.group,
}
}

func (h *GoKitHandler) WithGroup(name string) slog.Handler {
Expand All @@ -100,7 +105,12 @@ func (h *GoKitHandler) WithGroup(name string) slog.Handler {
g = h.group + "." + g
}

return &GoKitHandler{logger: h.logger, preformatted: h.preformatted, group: g}
return &GoKitHandler{
logger: h.logger,
level: h.level,
preformatted: h.preformatted,
group: g,
}
}

func appendPair(pairs []any, groupPrefix string, attr slog.Attr) []any {
Expand Down

0 comments on commit 705216f

Please sign in to comment.