chore: migrate from zerolog to log/slog#42
Open
vdaviot wants to merge 3 commits into
Open
Conversation
Replace `github.com/rs/zerolog` with the standard library `log/slog` in the integration test binaries (`tests/integration/`). The importable `pkg/` library code has no logging and is unaffected. - Drop direct dependency on `github.com/rs/zerolog` (still pulled in transitively by the `mockery` dev tool under the `tools` build tag, so it remains as `// indirect` in go.mod after `go mod tidy`). - Use `slog.NewJSONHandler` for JSON output, matching prior format. - Convert all log call-sites to typed `slog.Attr` helpers (`slog.String`, `slog.Any`, ...) and the `*Context` methods, threading a `context.Context` through the tester methods. - Rename the implicit zerolog `error` field to `error_message` to align with the logger-field-naming convention. - Map zerolog `Fatal()` to `ErrorContext(...)` + `os.Exit(1)` since `log/slog` does not provide a Fatal level. Note on public API: the `*zerolog.Logger` parameters that change to `*slog.Logger` (`NewSoftwareRAIDControllerTester`, and `runSoftwareControllerIntegrationTestSuite`) are in `package main` inside `tests/integration/`, so they are not importable by external consumers. There is no breaking change to `github.com/scality/raidmgmt`'s public API surface for downstream callers such as `platform-raid-report-generator`. Co-authored-by: Cursor <cursoragent@cursor.com>
Align the dead commented-out logging call with the rest of the migrated file (uses `InfoContext(ctx, ...)` instead of zerolog's fluent `.Info().Msg(...)`). Behavior unchanged. Co-authored-by: Cursor <cursoragent@cursor.com>
Use the shorter `error` key for the wrapped error attribute on `*Context` log calls, matching the convention adopted PR-wide. Co-authored-by: Cursor <cursoragent@cursor.com>
ezekiel-alexrod
approved these changes
May 21, 2026
| physicalDrives, err := t.controller.PhysicalDrives(&raidcontroller.Metadata{}) | ||
| if err != nil { | ||
| l.Error().Err(err).Msg("failed to get physical drives") | ||
| l.ErrorContext(ctx, "failed to get physical drives", slog.Any("error", err)) |
Contributor
There was a problem hiding this comment.
The log messages could be more readable by going for new lines
Suggested change
| l.ErrorContext(ctx, "failed to get physical drives", slog.Any("error", err)) | |
| l.ErrorContext(ctx, "failed to get physical drives", | |
| slog.Any("error", err), | |
| ) |
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.
Summary
github.com/rs/zerologwith the standard librarylog/slogin the integration test binaries (tests/integration/). The importablepkg/library code has no logging and is unaffected.github.com/rs/zerolog; it remains as// indirectaftergo mod tidybecause themockerydev tool pulls it in under thetoolsbuild tag.slog.NewJSONHandlerto preserve JSON output, convert call-sites to the typedslog.Attrhelpers and the*Contextmethods, and rename the impliciterrorfield toerror_messageto match thelogger-field-namingrule.zerolog.Fatal()is mapped toErrorContext(...)+os.Exit(1)sincelog/sloghas no Fatal level.Notes (public API)
The two function signatures that changed from
*zerolog.Loggerto*slog.Logger(NewSoftwareRAIDControllerTesterandrunSoftwareControllerIntegrationTestSuite) both live inpackage maininsidetests/integration/, so they are not importable by external consumers. There is no breaking change togithub.com/scality/raidmgmt's public API surface for downstream callers such asplatform-raid-report-generator— thepkg/packages do not expose any logger types.Log messages and log levels are preserved verbatim (with the single Fatal → Error+Exit mapping noted above). All field keys are snake_case as required.
Test plan
go build ./...go vet ./...go test ./...golangci-lint run ./tests/integration/...(0 issues on changed files; pre-existing unrelated issues inpkg/implementation/...are untouched)Made with Cursor