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

migrate to log/slog package #211

Open
thapabishwa opened this issue Dec 13, 2023 · 5 comments
Open

migrate to log/slog package #211

thapabishwa opened this issue Dec 13, 2023 · 5 comments

Comments

@thapabishwa
Copy link

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.

@TLINDEN
Copy link

TLINDEN commented Jan 13, 2024

I second that, fmt.Println() doesn't help as I already use log/slog everywhere.

Thanks!

@whrss9527
Copy link

#231

@christiangda
Copy link

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

}

@mitar
Copy link

mitar commented Dec 7, 2024

This does not allow use of logger from context, so any extra structured data in the logger is not used.

@imjasonh
Copy link

imjasonh commented Jan 8, 2025

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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants