Documentation
¶
Overview ¶
Package logging contains shared environment variable and log functionality.
Index ¶
- Constants
- func DataSourceContext(ctx context.Context, dataSource string) context.Context
- func InitContext(ctx context.Context, sdkOpts tfsdklog.Options, providerOpts tflog.Options) context.Context
- func ProtocolData(ctx context.Context, dataDir string, rpc string, message string, field string, ...)
- func ProtocolError(ctx context.Context, msg string, args ...interface{})
- func ProtocolTrace(ctx context.Context, msg string, args ...interface{})
- func ProtocolVersionContext(ctx context.Context, protocolVersion string) context.Context
- func ProviderAddressContext(ctx context.Context, providerAddress string) context.Context
- func ProviderLoggerName(providerAddress string) string
- func RequestIdContext(ctx context.Context) context.Context
- func ResourceContext(ctx context.Context, resource string) context.Context
- func RpcContext(ctx context.Context, rpc string) context.Context
Constants ¶
const ( // EnvTfLogProvider is the prefix of the environment variable that sets the // logging level of the root provider logger for the provider being served. // The suffix is an underscore and the parsed provider name. For example, // registry.terraform.io/hashicorp/example becomes TF_LOG_PROVIDER_EXAMPLE. EnvTfLogProvider = "TF_LOG_PROVIDER" // EnvTfLogSdk is an environment variable that sets the root logging level // of SDK loggers. EnvTfLogSdk = "TF_LOG_SDK" // EnvTfLogSdkProto is an environment variable that sets the logging level // of SDK protocol loggers. Infers root SDK logging level, if unset. EnvTfLogSdkProto = "TF_LOG_SDK_PROTO" // EnvTfLogSdkProtoDataDir is an environment variable that sets the // directory to write raw protocol data files for debugging purposes. EnvTfLogSdkProtoDataDir = "TF_LOG_SDK_PROTO_DATA_DIR" )
Environment variables.
const ( // A unique ID for the RPC request KeyRequestID = "tf_req_id" // The full address of the provider, such as // registry.terraform.io/hashicorp/random KeyProviderAddress = "tf_provider_addr" // The RPC being run, such as "ApplyResourceChange" KeyRPC = "tf_rpc" // The type of resource being operated on, such as "random_pet" KeyResourceType = "tf_resource_type" // The type of data source being operated on, such as "archive_file" KeyDataSourceType = "tf_data_source_type" // Path to protocol data file, such as "/tmp/example.json" KeyProtocolDataFile = "tf_proto_data_file" // The protocol version being used, as a string, such as "6" KeyProtocolVersion = "tf_proto_version" )
Global logging keys attached to all requests.
Practitioners or tooling reading logs may be depending on these keys, so be conscious of that when changing them.
const (
// SubsystemProto is the tfsdklog subsystem name for protocol logging.
SubsystemProto = "proto"
)
Variables ¶
This section is empty.
Functions ¶
func DataSourceContext ¶
DataSourceContext injects the data source type into logger contexts.
func InitContext ¶
func InitContext(ctx context.Context, sdkOpts tfsdklog.Options, providerOpts tflog.Options) context.Context
InitContext creates SDK and provider logger contexts.
func ProtocolData ¶
func ProtocolData(ctx context.Context, dataDir string, rpc string, message string, field string, data interface{})
ProtocolData emits raw protocol data to a file, if given a directory.
The directory must exist and be writable, prior to invoking this function.
File names are in the format: {TIME}_{RPC}_{MESSAGE}_{FIELD}.{EXT}
func ProtocolError ¶
ProtocolError emits a protocol subsystem log at ERROR level.
func ProtocolTrace ¶
ProtocolTrace emits a protocol subsystem log at TRACE level.
func ProtocolVersionContext ¶
ProtocolVersionContext injects the protocol version into logger contexts.
func ProviderAddressContext ¶
ProviderAddressContext injects the provider address into logger contexts.
func ProviderLoggerName ¶
func RequestIdContext ¶
RequestIdContext injects a unique request ID into logger contexts.
func ResourceContext ¶
ResourceContext injects the resource type into logger contexts.
Types ¶
This section is empty.