Skip to content
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

Add logging option to disable fields in log entry #631

Merged
merged 12 commits into from
Sep 19, 2023
Prev Previous commit
Next Next commit
refactor
Signed-off-by: Coleen Iona Quadros <coleen.quadros27@gmail.com>
  • Loading branch information
coleenquadros committed Sep 6, 2023
commit c8c5b974a0c0c848a25c850c1d860a2a3cf15a2d
3 changes: 2 additions & 1 deletion interceptors/logging/interceptors.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,9 @@ func reportable(logger Logger, opts *options) interceptors.CommonReportableFunc
fields = fields.WithUnique(customCommonFields(kind, c, opts.grpcLogFields()))
} else {
// Field dups from context override the common fields.
fields = newCommonFields(kind, c).WithUnique(ExtractFields(ctx))
fields = newCommonFields(kind, c)
}
fields = fields.WithUnique(ExtractFields(ctx))

if !c.IsClient {
if peer, ok := peer.FromContext(ctx); ok {
Expand Down
15 changes: 9 additions & 6 deletions interceptors/logging/logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,17 @@ func newCommonFields(kind string, c interceptors.CallMeta) Fields {
func customCommonFields(kind string, c interceptors.CallMeta, customFields []string) Fields {
commonFields := newCommonFields(kind, c)

existing := map[any]any{}
coleenquadros marked this conversation as resolved.
Show resolved Hide resolved
i := commonFields.Iterator()
for i.Next() {
k, v := i.At()
existing[k] = v
}

newFields := Fields{}
for _, key := range customFields {
commonFieldIterator := commonFields.Iterator()
for commonFieldIterator.Next() {
ck, cv := commonFieldIterator.At()
if ck == key {
newFields = append(newFields, ck, cv)
}
if _, ok := existing[key]; ok {
newFields = append(newFields, key, existing[key])
}
coleenquadros marked this conversation as resolved.
Show resolved Hide resolved
}
return newFields
Expand Down