fix(v2/log): Replace panic with slog.Default() fallback in FromContext
What does this MR do and why?
Problem
log.FromContext panics when called on a context that hasn't
been seeded with a logger via WithLogger. This forces every
consumer — including every test file — to defensively seed
contexts before any code path that touches logging. In
gitlab-shell alone, the labkit/v2 migration required adding
boilerplate in 11+ test call sites across 6 files.
Solution
Return slog.Default() when no logger is found in context,
following the precedent set by commit 4922f016 which replaced
a panic with a graceful New() fallback in WithFields for
the same safety reasons. The standard library's slog package
itself follows this philosophy.
References
- Commit
4922f016— prior precedent for replacing panic with graceful fallback inv2/log
Screenshots or screen recordings
Not applicable — no UI changes.
How to set up and validate locally
cd v2 && go test ./log/...- Verify all tests pass, including the updated
TestFromContext/returns_slog.Default_when_logger_not_in_contexttest.
MR acceptance checklist
Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.