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

Rework the SetField(key, val) function to use a dedicated map[string]interface{} to store implicit arguments #75

Closed
detro opened this issue Jul 14, 2022 · 1 comment · Fixed by #81
Assignees
Labels
enhancement New feature or request
Milestone

Comments

@detro
Copy link
Contributor

detro commented Jul 14, 2022

terraform-plugin-log version

0.6.0

Use cases

The objective is to refactor and simplify the internal logic of the logging library, when it comes to handling implicit arguments: key/value pairs that are added as a map to each log entries produced by a logger.

Currently, we rely on hclog own backing store: a []interface{}, where elements in odd positions are keys, and elements in even position are values. Yes, it's kind of error prone and makes writing logic around it a bit brittle.

This came to light prominently as part of the work of #71 (log filtering).

Proposal

  • Create a backing store for key/value pairs of arguments, inside the internal/logging LoggerOpts struct (similar to what we do for lot omission/masking): a map[string]interface{} type
  • Modify the SetField() method to set those key / value pairs inside the new backing store, instead of the hclog Logger.With() implicit arguments
  • Modify all the logging methods (Trace(), Debug(), ...) to get the key/value pairs from the new backing store
  • Rework the log filtering logic to make use of the new source of truth for key/value pairs, avoiding any operations around hclog Logger.ImplicitArgs(): this is ok, as our library interface will simply never place any value inside that slice anymore

References

#71

@detro detro added the enhancement New feature or request label Jul 14, 2022
@detro detro changed the title Rework the With(key, val) function to use a dedicated map[string]interface{} to store implicit arguments Rework the SetField(key, val) function to use a dedicated map[string]interface{} to store implicit arguments Jul 14, 2022
@detro detro self-assigned this Jul 14, 2022
@detro detro added this to the v0.6.0 milestone Jul 14, 2022
@detro detro closed this as completed in #81 Jul 15, 2022
@github-actions
Copy link

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.
If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 15, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant