tfsdklog: Introduce outside context level checks for logging functions #149
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Reference: hashicorp/terraform-plugin-framework#721
This change introduces log level checks outside the
context.Context
of a request to improve the performance of logging functions when logs would not be emitted at the configured level. Almost exclusively, logging levels are not expected to change during provider (and therefore SDK) runtime since they are environment variable driven. Even if they did, this level check will either immediately constrict logging to match an updated higher level or cause additionalcontext.Context
reads with an updated lower level, which is no different than the current behavior.The following benchmark was ran prior to the introduction of the level checks and mutexes:
After the addition of level checks and mutexes:
This enhancement could also be considered for provider loggers, however SDK logging tends to be more prevalent in practice, so this only targets the
tfsdklog
package handling.