Skip to content

replace logrus with log/slog across all packages (#1)#81

Open
Nicolas-Peiffer wants to merge 1 commit into
ThalesGroup:masterfrom
nicop311:master
Open

replace logrus with log/slog across all packages (#1)#81
Nicolas-Peiffer wants to merge 1 commit into
ThalesGroup:masterfrom
nicop311:master

Conversation

@Nicolas-Peiffer

@Nicolas-Peiffer Nicolas-Peiffer commented May 21, 2026

Copy link
Copy Markdown
Collaborator
  • replace logrus with log/slog across all packages

Migrate all logging calls from github.com/sirupsen/logrus to the standard library log/slog (Go 1.21+). Key changes:

  • Add pkg/logging package with LevelTrace = slog.Level(-8) constant and ParseLevel helper shared across cmd and provider packages
  • Add github.com/lmittmann/tint for colored text handler (replaces logrus text formatter with color support)
  • Replace logrus-filename hook with slog.HandlerOptions{AddSource: true}
  • Rename version.LogrusOutputVersion() to version.LogVersion()
  • Accept log levels: trace, debug, info, warn, error, quiet (drop logrus-specific: warning, fatal, panic)
  • logrus.Fatal → slog.Error + os.Exit(1)
  • logrus.Trace/Tracef → slog.Log(ctx, logging.LevelTrace, ...)
  • logrus.WithFields/WithField/WithError → inline slog key-value pairs
  • Remove github.com/keepeye/logrus-filename from go.mod
  • logrus remains only as an indirect dependency (pulled by other modules)

https://claude.ai/code/session_01BDmDyCyMiNjx4HMQwPWv7s

  • Improve slog usage: structured args, snake_case keys, Fatal helper, LevelVar
  • Add logging.Fatal helper (slog.Error + os.Exit(1)) to pkg/logging
  • Add activeLogLevel (*slog.LevelVar) in root.go for runtime-adjustable level
  • Replace all fmt.Sprintf inside slog calls with structured key-value args
  • Fix slog.Error(err.Error()) anti-pattern throughout; pass err as "error" attr
  • Fix nil-panic bug in istio.go GenerateDEK (err was nil when request==nil)
  • Rename all log keys to snake_case: cobra-cmd→cobra_cmd, keyId→key_id, etc.
  • Use real gRPC ctx instead of context.Background() in Encrypt method traces
  • Replace slog.Error+os.Exit(1) patterns with logging.Fatal in serve/rotation/test
  • Drop unused fmt and os imports where no longer needed

https://claude.ai/code/session_01BDmDyCyMiNjx4HMQwPWv7s

  • Update copyright year to 2026 in modified files

https://claude.ai/code/session_01BDmDyCyMiNjx4HMQwPWv7s

  • logging: add quiet level that discards all output

Introduce logging.LevelQuiet (slog.Level(math.MaxInt)) and wire it up so that --log-level=quiet installs slog.DiscardHandler, producing no log output at all.

  • pkg/logging: add LevelQuiet constant, "quiet" case in ParseLevel
  • cmd/root.go: detect LevelQuiet in initConfig and short-circuit with slog.DiscardHandler; update --log-level flag description and shell completion to include "quiet"

https://claude.ai/code/session_01BDmDyCyMiNjx4HMQwPWv7s


Proposed Changes

Types of Changes

Verification

Testing

Linked Issues

#48

User-Facing Change


Further Comments

gose and crypto11 will soon replace logrus by log/slog.

* replace logrus with log/slog across all packages

Migrate all logging calls from github.com/sirupsen/logrus to the
standard library log/slog (Go 1.21+). Key changes:

- Add pkg/logging package with LevelTrace = slog.Level(-8) constant
  and ParseLevel helper shared across cmd and provider packages
- Add github.com/lmittmann/tint for colored text handler (replaces
  logrus text formatter with color support)
- Replace logrus-filename hook with slog.HandlerOptions{AddSource: true}
- Rename version.LogrusOutputVersion() to version.LogVersion()
- Accept log levels: trace, debug, info, warn, error, quiet
  (drop logrus-specific: warning, fatal, panic)
- logrus.Fatal → slog.Error + os.Exit(1)
- logrus.Trace/Tracef → slog.Log(ctx, logging.LevelTrace, ...)
- logrus.WithFields/WithField/WithError → inline slog key-value pairs
- Remove github.com/keepeye/logrus-filename from go.mod
- logrus remains only as an indirect dependency (pulled by other modules)

https://claude.ai/code/session_01BDmDyCyMiNjx4HMQwPWv7s

* Improve slog usage: structured args, snake_case keys, Fatal helper, LevelVar

- Add logging.Fatal helper (slog.Error + os.Exit(1)) to pkg/logging
- Add activeLogLevel (*slog.LevelVar) in root.go for runtime-adjustable level
- Replace all fmt.Sprintf inside slog calls with structured key-value args
- Fix slog.Error(err.Error()) anti-pattern throughout; pass err as "error" attr
- Fix nil-panic bug in istio.go GenerateDEK (err was nil when request==nil)
- Rename all log keys to snake_case: cobra-cmd→cobra_cmd, keyId→key_id, etc.
- Use real gRPC ctx instead of context.Background() in Encrypt method traces
- Replace slog.Error+os.Exit(1) patterns with logging.Fatal in serve/rotation/test
- Drop unused fmt and os imports where no longer needed

https://claude.ai/code/session_01BDmDyCyMiNjx4HMQwPWv7s

* Update copyright year to 2026 in modified files

https://claude.ai/code/session_01BDmDyCyMiNjx4HMQwPWv7s

* logging: add quiet level that discards all output

Introduce logging.LevelQuiet (slog.Level(math.MaxInt)) and wire it up
so that --log-level=quiet installs slog.DiscardHandler, producing no
log output at all.

- pkg/logging: add LevelQuiet constant, "quiet" case in ParseLevel
- cmd/root.go: detect LevelQuiet in initConfig and short-circuit with
  slog.DiscardHandler; update --log-level flag description and shell
  completion to include "quiet"

https://claude.ai/code/session_01BDmDyCyMiNjx4HMQwPWv7s

---------

Co-authored-by: Claude <noreply@anthropic.com>
@Nicolas-Peiffer Nicolas-Peiffer self-assigned this May 21, 2026
@Nicolas-Peiffer Nicolas-Peiffer requested review from IceManGreen and cdanger and removed request for IceManGreen and cdanger May 21, 2026 08:39
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.

3 participants