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

[log] WithLogFields for Configuring Larger Logging Contexts #139

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

onelapahead
Copy link
Contributor

In several case, one might want to set several key value pairs on the context. Currently you have to chain together nested WithLogField funcs to do so, which isn't very readable or user friendly.

This allows the users to do so with just a list of strings. Otherwise we could require a logrus.Fields struct to be directly provided if we want to avoid the odd-number-check-and-panic ?

@@ -48,6 +48,24 @@ func WithLogField(ctx context.Context, key, value string) context.Context {
return WithLogger(ctx, loggerFromContext(ctx).WithField(key, value))
}

func WithLogFields(ctx context.Context, keyValues ...string) context.Context {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having ...string is fine to be consistent with WithLogField but it doesn't stop us having logrus.Fields one

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants