Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add log.ToLogger and log.ToSlogger helper functions #3629

Merged
merged 1 commit into from
Nov 19, 2024

Conversation

mcastorina
Copy link
Collaborator

Description:

Adds helper functions for converting our logger into other forms of stdlib logging.

Checklist:

  • Tests passing (make test-community)?
  • Lint passing (make lint this requires golangci-lint)?

@mcastorina mcastorina requested a review from a team as a code owner November 19, 2024 20:42
@@ -184,6 +186,16 @@ func WithGlobalRedaction() func(*sinkConfig) {
}
}

// ToLogger converts the logr.Logger into a legacy *log.Logger.
func ToLogger(l logr.Logger) *log.Logger {
return slog.NewLogLogger(logr.ToSlogHandler(l), slog.LevelInfo)
Copy link
Collaborator

Choose a reason for hiding this comment

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

question: I might be missing something or there are too many logs/slogs combos 🤣 , but should this be log. or should the comment be updated.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It compiles so it's correct, lol! It's doing logr.Logger -> slog.Handler -> *log.Logger.

The slog package has a function to "bridge" slog to the old log lib. See slog.NewLogLogger.

The logger acts as a bridge from the older log API to newer structured logging handlers.

@mcastorina mcastorina merged commit fe43c5d into main Nov 19, 2024
13 checks passed
@mcastorina mcastorina deleted the log-conversion-funcs branch November 19, 2024 22:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants