Skip to content

fix(contrib): resolve slog.Default() lazily to respect LOG_LEVEL=debug#69

Open
arnaugiralt wants to merge 1 commit intomasterfrom
fix/lazy-logger-contrib
Open

fix(contrib): resolve slog.Default() lazily to respect LOG_LEVEL=debug#69
arnaugiralt wants to merge 1 commit intomasterfrom
fix/lazy-logger-contrib

Conversation

@arnaugiralt
Copy link
Member

Contrib components were capturing slog.Default() at construction time and storing it as a struct field. Because plugins are constructed before chaperone.Run() calls configureLogging(), all contrib debug logs were silently discarded when LOG_LEVEL=debug was set.

Replace the eager-capture pattern with a log() helper method on each struct that calls slog.Default() at emit time. An explicit Logger in the config is used as-is; a nil Logger defers to whichever logger is currently installed globally.

Affected construction sites:

  • mux.go: NewMux() no longer pre-captures slog.Default()
  • static_mapping.go: NewStaticMapping() no longer pre-captures slog.Default()
  • microsoft/token.go: NewRefreshTokenSource() no longer pre-captures slog.Default()
  • oauthutil/token.go: NewTokenFetcher() no longer pre-captures slog.Default()
  • oauth/token.go: tokenManager.log() added for lazy resolution
  • oauth/refreshtoken.go: RefreshToken.log() added for lazy resolution

Fixes LITE-33931.

Contrib components were capturing slog.Default() at construction time
and storing it as a struct field. Because plugins are constructed before
chaperone.Run() calls configureLogging(), all contrib debug logs were
silently discarded when LOG_LEVEL=debug was set.

Replace the eager-capture pattern with a log() helper method on each
struct that calls slog.Default() at emit time. An explicit Logger in the
config is used as-is; a nil Logger defers to whichever logger is
currently installed globally.

Affected construction sites:
- mux.go: NewMux() no longer pre-captures slog.Default()
- static_mapping.go: NewStaticMapping() no longer pre-captures slog.Default()
- microsoft/token.go: NewRefreshTokenSource() no longer pre-captures slog.Default()
- oauthutil/token.go: NewTokenFetcher() no longer pre-captures slog.Default()
- oauth/token.go: tokenManager.log() added for lazy resolution
- oauth/refreshtoken.go: RefreshToken.log() added for lazy resolution

Fixes LITE-33931.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@arnaugiralt arnaugiralt requested a review from qarlosh March 13, 2026 11:30
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