From 63e5ba01ff2a205eb4769acba2f0a54f678d5f84 Mon Sep 17 00:00:00 2001 From: TJ Hoplock Date: Tue, 26 Nov 2024 09:27:46 -0500 Subject: [PATCH] docs: add godocs Signed-off-by: TJ Hoplock --- handler.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/handler.go b/handler.go index a926595..e998c2a 100644 --- a/handler.go +++ b/handler.go @@ -41,6 +41,8 @@ func NewGoKitHandler(logger log.Logger, level slog.Leveler) slog.Handler { return &GoKitHandler{logger: logger, level: level} } +// Enabled returns true if the internal slog.Leveler is enabled for the +// provided log level. It implements slog.Handler. func (h *GoKitHandler) Enabled(_ context.Context, level slog.Level) bool { if h.level == nil { h.level = &slog.LevelVar{} // Info level by default. @@ -49,6 +51,10 @@ func (h *GoKitHandler) Enabled(_ context.Context, level slog.Level) bool { return level >= h.level.Level() } +// Handler take an slog.Record created by an slog.Logger and dispatches the log +// call to the internal go-kit logger. Groups and attributes created by slog +// are formatted and added to the log call as individual key/value pairs. It +// implements slog.Handler. func (h *GoKitHandler) Handle(_ context.Context, record slog.Record) error { if h.logger == nil { h.logger = defaultGoKitLogger @@ -77,6 +83,8 @@ func (h *GoKitHandler) Handle(_ context.Context, record slog.Record) error { return logger.Log(pairs...) } +// WithAttrs formats the provided attributes and caches them in the handler to +// attach to all future log calls. It implements slog.Handler. func (h *GoKitHandler) WithAttrs(attrs []slog.Attr) slog.Handler { pairs := make([]any, 0, 2*len(attrs)) for _, a := range attrs { @@ -95,6 +103,8 @@ func (h *GoKitHandler) WithAttrs(attrs []slog.Attr) slog.Handler { } } +// WithGroup sets the group prefix string and caches it within the handler to +// use to prefix all future log attribute pairs. It implements slog.Handler. func (h *GoKitHandler) WithGroup(name string) slog.Handler { if name == "" { return h