Skip to content

chore: migrate from zerolog to log/slog#42

Open
vdaviot wants to merge 3 commits into
mainfrom
improvement/replace-zerolog-slog
Open

chore: migrate from zerolog to log/slog#42
vdaviot wants to merge 3 commits into
mainfrom
improvement/replace-zerolog-slog

Conversation

@vdaviot
Copy link
Copy Markdown
Contributor

@vdaviot vdaviot commented May 21, 2026

Summary

  • 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 the direct dependency on github.com/rs/zerolog; it remains as // indirect after go mod tidy because the mockery dev tool pulls it in under the tools build tag.
  • Use slog.NewJSONHandler to preserve JSON output, convert call-sites to the typed slog.Attr helpers and the *Context methods, and rename the implicit error field to error_message to match the logger-field-naming rule. zerolog.Fatal() is mapped to ErrorContext(...) + os.Exit(1) since log/slog has no Fatal level.

Notes (public API)

The two function signatures that changed from *zerolog.Logger to *slog.Logger (NewSoftwareRAIDControllerTester and runSoftwareControllerIntegrationTestSuite) both live 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 — the pkg/ 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 in pkg/implementation/... are untouched)

Made with Cursor

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>
@vdaviot vdaviot requested a review from a team as a code owner May 21, 2026 12:00
vdaviot and others added 2 commits May 21, 2026 14:04
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>
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))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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),
)

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.

2 participants