From 705216fd7e714e1bb20feb67e3b2c40a2d65aac2 Mon Sep 17 00:00:00 2001 From: TJ Hoplock Date: Fri, 22 Nov 2024 10:39:32 -0500 Subject: [PATCH] fix: retain level when using WithAttrs/WithGroup 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 --- handler.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/handler.go b/handler.go index 200f2f2..a926595 100644 --- a/handler.go +++ b/handler.go @@ -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 { @@ -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 {