From 9d10f385b5f7e487c6b62f0a3b88f1734565b22f Mon Sep 17 00:00:00 2001 From: Savely Krendelhoff Date: Sat, 23 Aug 2025 12:46:01 +0700 Subject: [PATCH] [PHASE-6] Add logger helper --- internal/lib/sl/sl.go | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 internal/lib/sl/sl.go diff --git a/internal/lib/sl/sl.go b/internal/lib/sl/sl.go new file mode 100644 index 0000000..4a91b7d --- /dev/null +++ b/internal/lib/sl/sl.go @@ -0,0 +1,27 @@ +package sl + +import ( + "context" + "log/slog" +) + +// Err creates a structured error attribute for slog +func Err(err error) slog.Attr { + return slog.Attr{ + Key: "error", + Value: slog.StringValue(err.Error()), + } +} + +// MockHandler is a test handler that discards all log messages +type MockHandler struct{} + +func (h *MockHandler) Enabled(context.Context, slog.Level) bool { return false } +func (h *MockHandler) Handle(context.Context, slog.Record) error { return nil } +func (h *MockHandler) WithAttrs([]slog.Attr) slog.Handler { return h } +func (h *MockHandler) WithGroup(string) slog.Handler { return h } + +// NewMockLogger creates a logger that discards all messages for testing +func NewMockLogger() *slog.Logger { + return slog.New(&MockHandler{}) +}