Conversation
Signed-off-by: Jason Hall <[email protected]>
There was a problem hiding this comment.
Pull Request Overview
This PR documents and demonstrates using Go 1.24’s t.Context() with clog instead of the legacy slogtest.Context, and updates the slogtest package accordingly.
- Add
TestSlogTestTContextto show how to configure the defaultsloglogger for use witht.Context(). - Extend the
slogtestpackage: bump theLoggerinterface to includeContext(), updateContextto wrapt.Context(), and update package docs. - Bump the module’s Go version directive to 1.24.4.
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| slogtest/slogtest_test.go | Added new test demonstrating t.Context() usage and imported log/slog. |
| slogtest/slogtest.go | Extended Logger interface with Context(), updated Context func, and added docs. |
| slogtest/another_test.go | Added fn helper to show context-based logging propagation. |
| go.mod | Updated Go directive from 1.22.4 to 1.24.4. |
Comments suppressed due to low confidence (1)
slogtest/slogtest.go:46
- The code refers to
context.Contextbut thecontextpackage isn't imported. Please addimport "context"to the import block.
Context() context.Context
wlynch
approved these changes
Aug 20, 2025
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.
Go 1.24 added
t.Context(), which is presumably more idiomatic to use with clog than our own slogtest package.This PR adds a comment mentioning
t.Contextand demonstrates how to gett.Contextto have the same behavior asslogtest.Context(t).Without the
slog.SetDefaultthe behavior is different:(debug logs are dropped, no file paths or line numbers, timestamps are added)
I don't know whether we should officially deprecate
slogtestin favor ofclog.FromContext(t.Context()), but at least this documents an off-ramp.