-
Notifications
You must be signed in to change notification settings - Fork 696
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
ctxzap: add convenience functions #407
Comments
Thanks for your issue! I think this sounds reasonable, though it's effectively the same as just replacing all your |
Correct. The main benefit comes from not having to argue about how this should be done over PRs, as well as indicating to users the golden path that prevents them from shooting their own foot (see the bit about interactions with other functions). Reducing visual noise is the icing on the cake. |
I'm not familiar enough with the package so say, but do we risk introducing confusing user behaviour? What happens if there's no logger in the context if you call |
go-grpc-middleware/logging/zap/ctxzap/context.go Lines 36 to 39 in a77ba4d
|
That's not terribly comforting but I guess we're not making things worse. Would you like to make this contribution? |
@johanbrandhorst opened #408 |
In our codebases some very common patterns are emerging.
Either:
or, especially if there is a single use of
logger
:The latter is not terrible, but it's repetitive and noisy. The former has some non-obvious interactions with other related functions (see below for details). And the existence of both ways to do the same thing leads to overhead (and sometimes bikeshedding) during code reviews. 😁
I would like to suggest, in the same spirit as
fmt
,math/rand
,net
,net/http
, and other packages in the standard library, to define convenience short-form versions of the most commonzap.Logger
methods (Debug
,Info
,Warn
,Error
), similar to:this would help unify the logging idiom (in most cases) to:
This may superficially look like a small improvement, but it compounds quickly for large/complex services. This is especially true for time spent in style discussions during code review, that in the past have also overlooked interactions between the "single
Extract
call" style (the first one at the top) and its non-obvious interactions withctxzap.AddFields
,ctxzap.ToContext
, and other calls toctxzap.Extract
.The text was updated successfully, but these errors were encountered: