hashicorp / go-retryablehttp

Retryable HTTP client in Go
Mozilla Public License 2.0
1.96k stars 246 forks source link

Using logrus as the custom logger #93

Open danielezer opened 4 years ago

danielezer commented 4 years ago

Is it possible to use a logrus logger as the custom logger? When I try, it seems like the logger is not used as a LeveledLogger, which is what I was expecting

juanfresia commented 4 years ago

Today I stumbled upon that as well. Apparently the interfaces do not match and I could not manage to get it to work without creating a wrapper for logrus, which is fine but kinda not what I expected.

Here is what I got (same thing with other methods):

cmd/root.go:17:3: cannot use logrus.StandardLogger() (type *logrus.Logger) as type retryablehttp.LeveledLogger in field value:
        *logrus.Logger does not implement retryablehttp.LeveledLogger (wrong type for Debug method)
                have Debug(...interface {})
                want Debug(string, ...interface {})

I don't know if there is a standard for logging interfaces in go, but logrus is pretty common and it would be nice to find a way to ease the integration without harming potential integration with other logging interfaces.

andreyvital commented 3 years ago

@danielezer here's what I've done:

retryClient.Logger = log.New(ioutil.Discard, "", log.LstdFlags)

retryClient.RequestLogHook = func(_ retryablehttp.Logger, req *http.Request, attempt int) {
    logger.WithFields(logrus.Fields{
        "request": map[string]string{
            "proto": req.Proto,
            "host":  req.URL.Host,
            "path":  req.URL.Path,
        },
        "attempt": attempt,
    }).Info("Sending request")
}
juanfresia commented 3 years ago

In case it helps anybody, I've made small changes in PR #101 to add a logger interface compatible with logrus "Printf-like" methods. That worked fine for me.

spykermj commented 3 years ago

This is not assigned after quite some time.

Is anyone going to work on this? Even if it is't logrus that is used, the fact that there are DEBUG messages I cannot turn off without some hack is pretty bad.

Can someone at least acknowledge this ticket?

sushinoya commented 3 years ago

@spykermj This is clearly an issue and should be assigned. I'm not a maintainer but I'm sure they will hopefully be able to get to it soon