go-grpc-middleware
go-grpc-middleware copied to clipboard
grpc_logrus: Use FieldLogger
Haven't checked the code yet, but I saw in the documentation that the logrus middleware awaits a logrus.Entry. Wouldn't it be better to rely on the logrus.FieldLogger interface?
gTBH it's relatively easy to pass in an Entry using https://godoc.org/github.com/sirupsen/logrus#NewEntry
What are the benefitsof logrus.FieldLogger above that?
It's an interface fulfilled by logrus.Entry and logrus.Logger as well. Also, I don't see how using Entry or Logger internals is necessary, so hiding those behind the FieldLogger API makes the code more stable by depending on a contract IMHO.
Sounds sensible. Wanna submit a PR? :)
Sure, but don't know when I will find some time to do so, so feel free to pick it if you want.
I started to take a stab at this, but the payload interceptor expects to be able to access the Data variable of a logrus.Entry returned from Extract:
logEntry := entry.WithFields(Extract(ctx).Data)
It might be possible to return a logrus.Entry for a logrus.FieldLogger by calling logrus.WithFields(logrus.Fields{}), but that feels dirty.
This is pretty old and we know have v2 code with different structure. Let us know if this is still important, we can reopen.