Closed thapabishwa-plerionaut closed 6 months ago
+1 for this feature, especially for the kubernetes ecosystem
@thapabishwa-plerionaut @halfcrazy Thanks for reaching out. I'm sorry for the delayed response.
Resty provides a Logger
interface for user choice of overriding.
https://github.com/go-resty/resty/blob/97187c431cf6db12100c49b68dab25bca79098c1/util.go#L31-L35
So you could assign your existing logger instance to it.
client := resty.New().SetLogger(...)
@jeevatkm
The interface you mentioned doesn't have the ability to interoperate with loggers(like gologr, klog, slog etc) that are used in kubernetes ecosystem.
package main
import (
"net/http"
"github.com/go-resty/resty/v2"
"sigs.k8s.io/controller-runtime/pkg/log"
)
func main() {
logger := log.Log.WithName("controller").WithName("mylogger")
/// cannot use logger (variable of type logr.Logger) as resty.Logger value in argument to resty.New().SetLogger: logr.Logger does not implement resty.Logger (missing method Debugf)
client := resty.New().SetLogger(logger)
cookies := []*http.Cookie{
&http.Cookie{
Name: "go-resty-1",
Value: "This is cookie 1 value",
},
&http.Cookie{
Name: "go-resty-2",
Value: "This is cookie 2 value",
},
}
client.SetCookies(cookies)
}
logr.Logger does not implement resty.Logger (missing method Debugf)
@thapabishwa Based on the error message, it seems logr does not have a Debugf implementation. I suggest creating a tiny wrapper for the log library you would like to use.
For example, refer to - https://github.com/go-resty/resty/blob/94e70d358df997ea7434b0856520dcfc14d3cf74/util.go#L37-L66
Currently, the
go-resty/resty
client does not supportgo-logr/logr
, a popular logging library for Go applications. This issue is created to propose and discuss the addition ofgo-logr/logr
support to thego-resty/resty
client.Motivation:
go-logr/logr
provides a flexible and extensible logging framework, allowing applications to use different log sinks and log levels. By adding support forgo-logr/logr
to thego-resty/resty
client, users can have more control and flexibility over logging in their applications.There are (non-exhaustive list of)implementations for the following logging libraries:
Proposed Changes: Example:
Expected Result: With this feature, users can integrate
go-resty/resty
seamlessly into their applications that use various implementations ofgo-logr/logr
for logging. This provides consistency in the logging framework and allows for better customization and control of log messages.Additional Context: Please note that this is just a proposal, and further discussion and development are needed to implement this feature. I encourage the community to share their thoughts, suggestions, or any potential challenges related to this feature request.