Repository navigation
feat(api)!: log the default instance through slog.Default - #72
Merged
Merged
Conversation
Second part of the owner decision (2026-11-21) that the default instance behaves like api.New(). The default instance now writes the same slog records as an instance with WithLogger, through slog.Default() read at call time; an api.New() without WithLogger still logs nothing. The last fromNew forks (logging, the response writer) are gone, so the default instance and instances share one code path. The v0 golden log test is replaced by golden slog records in default_instance_test.go. Deprecated: LogRequestBody, LogResponseBody, PrintFullEvent and MaxLoggedBodyBytes (they affect only the deprecated Log* functions). PrintError and Fatal are documented as ignored. TraceVisibility, TraceIDLength and BlankSuccess keep configuring the default instance and stay undeprecated (no replacement option). BREAKING CHANGE: for programs that use the package-level API without api.New (the default instance): - ProcessRequest, the body middlewares, the Get*Value* helpers and the response writer log slog records (request, response, request body rejected, panic recovered, ...) through slog.Default() instead of REQUEST/RESPONSE lines through Print and PrintError; - the package no longer calls PrintError (or Fatal); Print is called only by the deprecated LogRequest/LogResponse*. A program that assigned api.PrintError or api.Print to route logs must call slog.SetDefault or move to api.New(api.WithLogger(...)); - request and response bodies and the parsed form are never logged, even with LogRequestBody or LogResponseBody set; - SensitiveLogKeys adds keys to the built-in list and can no longer remove a built-in key; - a type that embeds ResponseWriter logs through slog.Default. Stay on v0.11.x to keep v0 behavior. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
josuegiron
changed the base branch from
feat/default-instance-wire
to
master
November 21, 2026 18:26
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Scope
PR 2 of 2. It is stacked on #71 and targets
feat/default-instance-wire. Merge #71 first, then retarget this PR tomaster. No tag.This PR covers the logging half of the owner decision (2026-11-21): the default instance behaves like
api.New(). After it lands, the default instance and instances share one code path, and nofromNewis left anywhere.Changes
slog.Default(), read at call time. It writes the same records as an instance withWithLogger:request,response,request body rejected,panic recovered,Get*Value*helper failures, andresponse cannot be encoded.SensitiveLogKeys, which can add keys but not remove one.api.New()withoutWithLoggerstill logs nothing:Newmaps the nil logger toslog.DiscardHandler.ResponseWriter.Write. The zero writer logs throughslog.Defaultand uses the registered formatter for its 500 body. The v0writeEncodeFailure/writeEncodedare deleted.LogRequestBody,LogResponseBody,PrintFullEvent,MaxLoggedBodyBytes. They now affect only the deprecatedLog*functions.PrintErrorandFatalare documented as ignored.Printis used only by the deprecatedLog*.TraceVisibility,TraceIDLengthandBlankSuccesskeep configuring the default instance and are not deprecated, because no option replaces them (constitution V).docs/legacy.mdanddoc.go.Breaking (default-instance users)
slogrecords go throughslog.Defaultinstead ofPrint/PrintErrorlines.api.PrintError,api.Printorapi.Fatalno longer routes the library's logs. Useslog.SetDefaultorapi.WithLogger.LogRequestBodyset.SensitiveLogKeyscan only add keys.Stay on v0.11.x to keep v0 behavior.
Tests
default_log_golden_test.go, the v0 lines, is replaced by golden slog records indefault_instance_test.go(TestDefaultInstanceLogsThroughSlogDefault). New tests:SensitiveLogKeysonly adds keys;New()stays silent under a capturing default logger;PrintandPrintErrorare never called.The writer, recover and logging tests were moved off
PrintError.Size
1,000 changed lines (503+/497−), at the PR-02 limit.
Verification
gofmt -l .prints nothing.go vet ./...passes.go test -race ./...passes in every package.govulncheck ./...finds no vulnerabilities.go test -bench=. -run='^$' -benchmem ./..., before (master) → after:The instance numbers are unchanged. The default instance now costs the same as an instance.
🤖 Generated with Claude Code