SK-2871: make slog logger thread-safe and match logrus output format - #199
Merged
Devesh-Skyflow merged 2 commits intoJul 13, 2026
Merged
Conversation
The logrus->slog migration introduced two consumer-facing regressions in
utils/logger:
- Data race: `log` was a plain package var reassigned by SetOutput/
SetLogLevel(OFF) while Debug/Info/Warn/Error read it. logrus guarded
this with an internal mutex; slog swaps the whole pointer. A shared
client calling UpdateLogLevel while other goroutines log would race
(confirmed under `go test -race`). Fixed by holding `log` in an
atomic.Pointer (lock-free logging path) and guarding writer/rebuild
with a mutex.
- Format change: slog's TextHandler emitted uppercase levels, "WARN"
instead of "warning", and an unquoted millisecond timestamp, breaking
any log parsing keyed on the old format. Added logrusTextHandler, a
minimal slog.Handler that reproduces logrus TextFormatter{FullTimestamp}
byte-for-byte: quoted RFC3339 (seconds) time, lowercase levels.
Tests: logger_concurrency_test.go guards the race (run with -race);
verify_behavior_test.go asserts level filtering and exact line format.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Extract logrus level-name string literals into constants (goconst) and the log-line buffer size into a named constant (revive add-constant). No behavior change. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.
The logrus->slog migration introduced two consumer-facing regressions in utils/logger:
logwas a plain package var reassigned by SetOutput/ SetLogLevel(OFF) while Debug/Info/Warn/Error read it. logrus guarded this with an internal mutex; slog swaps the whole pointer. A shared client calling UpdateLogLevel while other goroutines log would race (confirmed undergo test -race). Fixed by holdinglogin an atomic.Pointer (lock-free logging path) and guarding writer/rebuild with a mutex.Tests: logger_concurrency_test.go guards the race (run with -race); verify_behavior_test.go asserts level filtering and exact line format.