-
Notifications
You must be signed in to change notification settings - Fork 257
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
migrate to log/slog
package
#211
Comments
I second that, Thanks! |
Hi everyone, Here a Workarroung ... code omitted
var (
logHandler slog.Handler
logHandlerOptions *slog.HandlerOptions
logger *slog.Logger
)
... code omitted
// My logger type to implement 'httpRetryableClient.Logger '
type retryableLogger struct {
logger *slog.Logger
}
// Printf is the necessary method to implement 'httpRetryableClient.Logger '
func (r *retryableLogger) Printf(format string, args ...interface{}) {
r.logger.Debug(fmt.Sprintf(format, args...))
}
... code omitted
func main() {
logger = slog.New(logHandler)
slog.SetDefault(logger)
... code omitted
httpRetryableClient := retryablehttp.NewClient()
httpRetryableClient.RetryMax = HTTPClientConfig.MaxRetries.Value
httpRetryableClient.Backoff = retryablehttp.DefaultBackoff
httpRetryableClient.CheckRetry = retryablehttp.DefaultRetryPolicy
httpRetryableClient.Logger = &retryableLogger{logger: logger} // <----- assign the new slog logger
httpClient := httpRetryableClient.StandardClient()
.... code omitted
} |
This does not allow use of logger from context, so any extra structured data in the logger is not used. |
Would there be any interest from the maintainers in a PR from the community to make this change? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I hope this message finds you well! I wanted to open a discussion regarding the possibility of migrating to the
log/slog
package within the go-retrablehttp project. This migration could offer several benefits to the project, improving its maintainability and enhancing logging functionalities.Benefits of Using log/slog
Structured Logging: log/slog provides structured logging capabilities, enabling better organization and analysis of log data. This could significantly enhance the readability and comprehensibility of log entries within the project.
Contextual Logging: With the ability to add context to log messages, log/slog enables better traceability of events, aiding in debugging and troubleshooting.
Compatibility with Go 1.21: As Go evolves, staying updated with the latest features and functionalities is crucial. log/slog aligns with the direction Go is heading in version 1.21, ensuring compatibility and future-proofing the codebase.
Extensibility and Customization: The log/slog package offers various customization options, allowing the project to adapt logging behavior as per specific requirements.
The text was updated successfully, but these errors were encountered: