diff --git a/README.md b/README.md index 1c79a89..f73bd78 100644 --- a/README.md +++ b/README.md @@ -28,7 +28,7 @@ In that same workflow, the `HandlerOptions` and `AttrExtractor` types let us extract any custom values from a context and have them automatically be prepended or appended to all log lines using that context. By default, there are extractors for anything added via `Prepend` and `Append`, but this repository -contains more optional Extractors that can be added: +contains some optional Extractors that can be added: * `slogotel.ExtractTraceSpanID` extractor will automatically extract the OTEL (OpenTelemetry) TraceID and SpanID, and add them to the log record, while also annotating the Span with an error code if the log is at error level. diff --git a/handler_test.go b/handler_test.go index b8e410f..f06f01d 100644 --- a/handler_test.go +++ b/handler_test.go @@ -37,10 +37,12 @@ func TestHandler(t *testing.T) { l := slog.New(h) - l = l.With("with1", "arg1", "with1", "arg2") - l = l.WithGroup("group1") + l = l.With("with1", "arg1", "with1", "arg2").With() + l = l.WithGroup("group1").WithGroup("") l = l.With("with2", "arg1", "with2", "arg2") + l.Log(ctx, slog.LevelDebug-10, "ignored") + l.LogAttrs(ctx, slog.LevelDebug-10, "ignored") l.InfoContext(ctx, "main message", "main1", "arg1", "main1", "arg2") expectedText := `time=2023-09-29T13:00:59.000Z level=INFO msg="main message" prepend1=arg1 prepend1=arg2 prepend2=arg1 prepend2=arg2 with1=arg1 with1=arg2 group1.with2=arg1 group1.with2=arg2 group1.main1=arg1 group1.main1=arg2 group1.append1=arg1 group1.append1=arg2 group1.append2=arg1 group1.append2=arg2 @@ -75,7 +77,7 @@ func TestHandler(t *testing.T) { if unmarshalled.Source.Function != "github.com/veqryn/slog-context.TestHandler" || !strings.HasSuffix(unmarshalled.Source.File, "slog-context/handler_test.go") || - unmarshalled.Source.Line != 44 { + unmarshalled.Source.Line != 46 { t.Errorf("Expected source fields are incorrect: %#+v\n", unmarshalled) } } diff --git a/http/middleware_test.go b/http/middleware_test.go index c538ba0..7f38988 100644 --- a/http/middleware_test.go +++ b/http/middleware_test.go @@ -129,6 +129,7 @@ func TestOutsideRequest(t *testing.T) { ctx := slogctx.NewCtx(context.Background(), slog.New(h)) ctx = With(ctx, "id", "13579") + ctx = With(ctx) // Should be ignored slogctx.Info(ctx, "utility method") // should also have "id" diff --git a/internal/test/handler.go b/internal/test/handler.go index 7008b1a..de4307c 100644 --- a/internal/test/handler.go +++ b/internal/test/handler.go @@ -19,8 +19,8 @@ type Handler struct { } // Enabled returns true -func (h *Handler) Enabled(context.Context, slog.Level) bool { - return true +func (h *Handler) Enabled(_ context.Context, lvl slog.Level) bool { + return lvl >= slog.LevelDebug } // Handle records a log record