Skip to content

SK-2871: make slog logger thread-safe and match logrus output format - #199

Merged
Devesh-Skyflow merged 2 commits into
release/26.6.25from
devesh/sk-2871-fix-outdated-dependencies
Jul 13, 2026
Merged

SK-2871: make slog logger thread-safe and match logrus output format#199
Devesh-Skyflow merged 2 commits into
release/26.6.25from
devesh/sk-2871-fix-outdated-dependencies

Conversation

@Devesh-Skyflow

Copy link
Copy Markdown
Collaborator

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.

Devesh-Skyflow and others added 2 commits July 13, 2026 08:14
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>
@Devesh-Skyflow
Devesh-Skyflow merged commit 48308bb into release/26.6.25 Jul 13, 2026
3 of 4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant