-
-
Notifications
You must be signed in to change notification settings - Fork 4k
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
feat(log): add Logger() method for Helper #3443
Conversation
@shenqidebaozi feel free to comment something if you want |
I have communicated with @shenqidebaozi about this PR through other channels, and I'd like to sync the discussion content here: @shenqidebaozi believes that But I think the |
9fa2ffb
to
3df5801
Compare
@shenqidebaozi Hi, would you mind to take a look on this PR, maybe it's time to merge this |
Description
In the real world, some log fields have significant contextual relevance. A reasonable approach is to use
log.With
to attach fields and create a newLogger
, then convert it to*log.Helper
held by an object.For statically created Loggers, this works well; but for dynamically created Loggers, such as when an API request contains a user ID and we perform many operations for it, in order to easily query logs afterwards, we need to include his user ID at each logging point.
Because Service objects generally only contain
*log.Helper
, there is currently no public method to obtainlog.Logger
from*log.Helper
and add fields, and we have to pass all those fields to every logging point, which is quiet boring.Show case