logging

package
v1.11.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 19, 2024 License: MPL-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// EnvTfLogSdk is an environment variable that sets the logging level of
	// the root SDK logger, while the provider is under test. In "production"
	// usage, this environment variable is handled by terraform-plugin-go.
	//
	// Terraform CLI's logging must be explicitly turned on before this
	// environment varable can be used to reduce the SDK logging levels. It
	// cannot be used to show only SDK logging unless all other logging levels
	// are turned off.
	EnvTfLogSdk = "TF_LOG_SDK"

	// EnvTfLogSdkHelperResource is an environment variable that sets the logging
	// level of SDK helper/resource loggers. Infers root SDK logging level, if
	// unset.
	EnvTfLogSdkHelperResource = "TF_LOG_SDK_HELPER_RESOURCE"

	// EnvTfLogSdkHelperSchema is an environment variable that sets the logging
	// level of SDK helper/schema loggers. Infers root SDK logging level, if
	// unset.
	EnvTfLogSdkHelperSchema = "TF_LOG_SDK_HELPER_SCHEMA"
)

Environment variables.

View Source
const (
	// Attribute path representation, which is typically in flatmap form such
	// as parent.0.child in this project.
	KeyAttributePath = "tf_attribute_path"

	// The type of data source being operated on, such as "archive_file"
	KeyDataSourceType = "tf_data_source_type"

	// Underlying Go error string when logging an error.
	KeyError = "error"

	// The full address of the provider, such as
	// registry.terraform.io/hashicorp/random
	KeyProviderAddress = "tf_provider_addr"

	// The type of resource being operated on, such as "random_pet"
	KeyResourceType = "tf_resource_type"

	// The name of the test being executed.
	KeyTestName = "test_name"

	// The TestStep number of the test being executed. Starts at 1.
	KeyTestStepNumber = "test_step_number"

	// Terraform configuration used during acceptance testing Terraform operations.
	KeyTestTerraformConfiguration = "test_terraform_configuration"

	// The Terraform CLI logging level (TF_LOG) used for an acceptance test.
	KeyTestTerraformLogLevel = "test_terraform_log_level"

	// The Terraform CLI logging level (TF_LOG_CORE) used for an acceptance test.
	KeyTestTerraformLogCoreLevel = "test_terraform_log_core_level"

	// The Terraform CLI logging level (TF_LOG_PROVIDER) used for an acceptance test.
	KeyTestTerraformLogProviderLevel = "test_terraform_log_provider_level"

	// The path to the Terraform CLI logging file used for an acceptance test.
	//
	// This should match where the rest of the acceptance test logs are going
	// already, but is provided for troubleshooting in case it does not.
	KeyTestTerraformLogPath = "test_terraform_log_path"

	// The path to the Terraform CLI used for an acceptance test.
	KeyTestTerraformPath = "test_terraform_path"

	// Terraform plan output generated during a TestStep.
	KeyTestTerraformPlan = "test_terraform_plan"

	// The working directory of the acceptance test.
	KeyTestWorkingDirectory = "test_working_directory"
)

Structured logging keys.

Practitioners or tooling reading logs may be depending on these keys, so be conscious of that when changing them.

Refer to the terraform-plugin-go logging keys as well, which should be equivalent to these when possible.

View Source
const (
	// SubsystemHelperResource is the tfsdklog subsystem name for helper/resource.
	SubsystemHelperResource = "helper_resource"
)
View Source
const (
	// SubsystemHelperSchema is the tfsdklog subsystem name for helper/schema.
	SubsystemHelperSchema = "helper_schema"
)

Variables

This section is empty.

Functions

func HelperResourceDebug

func HelperResourceDebug(ctx context.Context, msg string, additionalFields ...map[string]interface{})

HelperResourceDebug emits a helper/resource subsystem log at DEBUG level.

func HelperResourceError

func HelperResourceError(ctx context.Context, msg string, additionalFields ...map[string]interface{})

HelperResourceError emits a helper/resource subsystem log at ERROR level.

func HelperResourceTrace

func HelperResourceTrace(ctx context.Context, msg string, additionalFields ...map[string]interface{})

HelperResourceTrace emits a helper/resource subsystem log at TRACE level.

func HelperResourceWarn

func HelperResourceWarn(ctx context.Context, msg string, additionalFields ...map[string]interface{})

HelperResourceWarn emits a helper/resource subsystem log at WARN level.

func HelperSchemaDebug

func HelperSchemaDebug(ctx context.Context, msg string, additionalFields ...map[string]interface{})

HelperSchemaDebug emits a helper/schema subsystem log at DEBUG level.

func HelperSchemaError

func HelperSchemaError(ctx context.Context, msg string, additionalFields ...map[string]interface{})

HelperSchemaError emits a helper/schema subsystem log at ERROR level.

func HelperSchemaTrace

func HelperSchemaTrace(ctx context.Context, msg string, additionalFields ...map[string]interface{})

HelperSchemaTrace emits a helper/schema subsystem log at TRACE level.

func HelperSchemaWarn

func HelperSchemaWarn(ctx context.Context, msg string, additionalFields ...map[string]interface{})

HelperSchemaWarn emits a helper/schema subsystem log at WARN level.

func InitContext

func InitContext(ctx context.Context) context.Context

InitContext creates SDK logger contexts when the provider is running in "production" (not under acceptance testing). The incoming context will already have the root SDK logger and root provider logger setup from terraform-plugin-go tf5server RPC handlers.

func InitTestContext

func InitTestContext(ctx context.Context, t testing.T) context.Context

InitTestContext registers the terraform-plugin-log/tfsdklog test sink, configures the standard library log package, and creates SDK logger contexts. The incoming context is expected to be devoid of logging setup.

The standard library log package handling is important as provider code under test may be using that package or another logging library outside of terraform-plugin-log.

func TestNameContext

func TestNameContext(ctx context.Context, testName string) context.Context

TestNameContext adds the current test name to loggers.

func TestStepNumberContext

func TestStepNumberContext(ctx context.Context, stepNumber int) context.Context

TestStepNumberContext adds the current test step number to loggers.

func TestTerraformPathContext

func TestTerraformPathContext(ctx context.Context, terraformPath string) context.Context

TestTerraformPathContext adds the current test Terraform CLI path to loggers.

func TestWorkingDirectoryContext

func TestWorkingDirectoryContext(ctx context.Context, workingDirectory string) context.Context

TestWorkingDirectoryContext adds the current test working directory to loggers.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL