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

Support whitelisting log lines via regular expressions #25086

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

PSanetra
Copy link

This PR makes it possible to whitelist log lines, matching regular expressions, defined in environment variables with a TF_LOG_PATTERN_ prefix.

Lines matching these patterns will be logged regardless of the defined log level in TF_LOG.

Example:
The following environment variable would whitelist log lines, which are logged by the helm terraform provider \[\w+\] plugin.terraform-provider-helm:
TF_LOG_PATTERN_HELM_PLUGIN=\[\w+\] plugin.terraform-provider-helm

This features helps with debugging plugins as you can easily define a pattern, which matches the log lines of you own plugin. A related issue does already exist: hashicorp/terraform-plugin-sdk#88

The feature can also be helpful in ci/cd pipelines if you are interested in debug log lines, which match a certain pattern.

@hashicorp-cla
Copy link

hashicorp-cla commented May 30, 2020

CLA assistant check
All committers have signed the CLA.

@codecov
Copy link

codecov bot commented May 30, 2020

Codecov Report

Merging #25086 into master will decrease coverage by 0.01%.
The diff coverage is 27.58%.

Impacted Files Coverage Δ
helper/logging/logging.go 0.00% <0.00%> (ø)
helper/resource/testing.go 30.81% <0.00%> (ø)
helper/logging/filter.go 82.50% <80.00%> (ø)
terraform/evaluate.go 53.15% <0.00%> (-0.46%) ⬇️
terraform/node_resource_plan.go 93.44% <0.00%> (+1.63%) ⬆️

pattern, err := regexp.Compile(envVarValue)

if err != nil {
log.Fatalln("Can not compile "+envVarName+":", err)
Copy link
Author

Choose a reason for hiding this comment

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

I am not sure if it is ok to panic if the pattern can not compile. But I guess the user expects terraform to fail if this is the case.

…_PATTERN_" prefix

This commit makes it possible to whitelist log lines, matching regular expressions, defined in environment variables.
Lines matching these patterns will be logged regardless of the defined log level in TF_LOG.

Example:
The following environment variable would whitelist log lines, which match the regular expression "\[\w+\] plugin.terraform-provider-helm"
TF_LOG_PATTERN_HELM_PLUGIN=\[\w+\] plugin.terraform-provider-helm
@PSanetra PSanetra force-pushed the support-whitelisted-log-patterns branch from 27598e1 to d81f7c2 Compare June 1, 2020 20:25
Base automatically changed from master to main February 24, 2021 18:01
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.

None yet

2 participants