feat(log): add Logger() method for Helper #3443
Draft
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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