go-grpc-middleware icon indicating copy to clipboard operation
go-grpc-middleware copied to clipboard

grpc_logrus: Use FieldLogger

Open sagikazarmark opened this issue 8 years ago • 5 comments

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?

sagikazarmark avatar May 30 '17 00:05 sagikazarmark

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?

mwitkow avatar Jun 01 '17 16:06 mwitkow

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.

sagikazarmark avatar Jun 01 '17 17:06 sagikazarmark

Sounds sensible. Wanna submit a PR? :)

mwitkow avatar Jun 09 '17 15:06 mwitkow

Sure, but don't know when I will find some time to do so, so feel free to pick it if you want.

sagikazarmark avatar Jun 09 '17 16:06 sagikazarmark

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.

mrbanzai avatar Sep 14 '17 16:09 mrbanzai

This is pretty old and we know have v2 code with different structure. Let us know if this is still important, we can reopen.

bwplotka avatar Mar 19 '23 01:03 bwplotka