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

Is this a bug? zap logging

Open wrapupc opened this issue 1 year ago • 3 comments

logger := zap.NewExample() return grpc.ChainUnaryInterceptor( logging.UnaryServerInterceptor(InterceptorZapLogger(logger)), )

I added zap into grpc interceptor, and here is what i got after a request

{"level":"info","msg":"started call","protocol":"grpc","protocol":"grpc","protocol":"grpc","protocol":"grpc","protocol":"grpc","protocol":"grpc","protocol":"grpc","protocol":"grpc"} {"level":"info","msg":"finished call","protocol":"grpc","protocol":"grpc","protocol":"grpc","protocol":"grpc","protocol":"grpc","protocol":"grpc","protocol":"grpc","protocol":"grpc","protocol":"grpc","p rotocol":"grpc","protocol":"grpc","protocol":"grpc","protocol":"grpc","protocol":"grpc","protocol":"grpc","protocol":"grpc","protocol":"grpc"}

wrapupc avatar Apr 11 '23 16:04 wrapupc

Hi, can you check latest tag (https://github.com/grpc-ecosystem/go-grpc-middleware/releases/tag/v2.0.0-rc.5)? We recommend now to create your own "logging.Logger" implementation, see https://github.com/grpc-ecosystem/go-grpc-middleware/tree/main/interceptors/logging/examples/zap

Let me know if you can still repro the problem with this new approach.

bwplotka avatar Apr 13 '23 10:04 bwplotka

I guess you actually found it in new version and fixed, nice!

https://github.com/grpc-ecosystem/go-grpc-middleware/pull/565#pullrequestreview-1383162951

bwplotka avatar Apr 13 '23 10:04 bwplotka

Hi, can you check latest tag (https://github.com/grpc-ecosystem/go-grpc-middleware/releases/tag/v2.0.0-rc.5)? We recommend now to create your own "logging.Logger" implementation, see https://github.com/grpc-ecosystem/go-grpc-middleware/tree/main/interceptors/logging/examples/zap

Let me know if you can still repro the problem with this new approach.

What's the motivation behind this? I've found myself copy-pasting this code multiple times in different projects. I think that it's one of those things that consumers of the different interceptors would be very happy to have without the need to copy paste code, mostly those users that don't have very complex use cases, they just want to consume this interceptor right away.

Instead of encouraging them to create their own library to export their own logging.Logger implementation and reuse them across project, I think it would be valuable to have it here, although I'd agree that it might be zap's responsibility instead.

marcoshuck avatar Nov 03 '23 03:11 marcoshuck