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

Adding With in logger to keep logging key/value pairs #578

Merged
merged 1 commit into from Dec 14, 2022

Conversation

ferruvich
Copy link
Contributor

What this PR does / why we need it:
Currently, the log package contains a very simple logger.
A common pattern in loggers is to re-use fields between logging statements, by creating "sub-loggers" that retain and always include wanted key/value pairs.

A way to achieve this would be to create a new function, called With, with the following signature

func (r *hclogWrapper) With(args ...interface{}) Logger

and use github.com/hashicorp/go-hclog Logger.With to build and return this new sub-logger.

Which issue(s) this PR fixes:

Fixes #577

@ferruvich ferruvich added enhancement New feature or request go Pull requests that update Go code labels Dec 12, 2022
@ferruvich ferruvich self-assigned this Dec 12, 2022
@ferruvich ferruvich requested a review from a team as a code owner December 12, 2022 14:49
@ferruvich ferruvich requested review from wbrowne and marefr and removed request for a team December 12, 2022 14:49
@CLAassistant
Copy link

CLAassistant commented Dec 12, 2022

CLA assistant check
All committers have signed the CLA.

@ferruvich ferruvich removed their assignment Dec 13, 2022
Copy link
Member

@marefr marefr left a comment

Choose a reason for hiding this comment

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

LGTM

@ferruvich ferruvich merged commit 66b268d into main Dec 14, 2022
@ferruvich ferruvich deleted the daniele/logger-with branch December 14, 2022 16:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request go Pull requests that update Go code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Logger to retain key/value pairs
4 participants