plugins icon indicating copy to clipboard operation
plugins copied to clipboard

Adding context using zaplogger results in the wrong type

Open neophiliac opened this issue 3 years ago • 3 comments

s.logger has type *log.Logger, which is a wrapper for *zap.SugaredLogger. Since the rest of the system is also using the same wrapper, everything is fine... until:

       logger := s.logger.With(
		"req", ctx.Value(middleware.RequestIDKey),
		"companyID", p.CompanyID,
		"vendorID", p.VendorID,
	)

Now logger has type *zap.SugaredLogger and can't be passed to functions that expect *log.Logger. It seems like it should be possible to cast it, but that gives me a type conversion error.

I'm pretty sure I'm missing something, but since the zaplogger plugin offers context logging it seems like this should work, and it might be useful to document the use of context logging in the calc example.

I'm using go 1.17.5, goa 3.5.3, and goa plugins v3.5.3. Thanks in advance!

neophiliac avatar Dec 31 '21 05:12 neophiliac

I would recommend only using the *log.Logger type when instantiating the Goa middleware and using the "native" zap logger for the rest of the code. The plugin might need a bit of tweaking to enable that, maybe @hirosassa has some ideas?

raphael avatar Jan 13 '22 17:01 raphael

Thank you for letting me know! I'll take a look tonight (I mean in JST).

hirosassa avatar Jan 13 '22 20:01 hirosassa

Is it solved?

mcauto avatar Aug 29 '22 08:08 mcauto

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

github-actions[bot] avatar Oct 29 '22 05:10 github-actions[bot]