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

Using logrus as the custom logger #93

Open
danielezer opened this issue May 3, 2020 · 5 comments
Open

Using logrus as the custom logger #93

danielezer opened this issue May 3, 2020 · 5 comments

Comments

@danielezer
Copy link

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
Copy link

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
Copy link

@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
Copy link

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
Copy link

spykermj commented May 2, 2021

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
Copy link

@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

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

5 participants