logging

package
v2.24.1 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2022 License: MPL-2.0 Imports: 18 Imported by: 124

Documentation

Index

Constants

View Source
const (
	EnvLog        = "TF_LOG"          // See ValidLevels
	EnvLogFile    = "TF_LOG_PATH"     // Set to a file
	EnvAccLogFile = "TF_ACC_LOG_PATH" // Set to a file
	// EnvLogPathMask splits test log files by name.
	EnvLogPathMask = "TF_LOG_PATH_MASK"
)

These are the environmental variables that determine if we log, and if we log whether or not the log should go to a file.

View Source
const (
	// FieldHttpOperationType is the field key used by NewLoggingHTTPTransport
	// and NewSubsystemLoggingHTTPTransport when logging the type of HTTP operation via tflog.
	FieldHttpOperationType = "tf_http_op_type"

	// OperationHttpRequest is the field value used by NewLoggingHTTPTransport
	// and NewSubsystemLoggingHTTPTransport when logging an HTTP request via tflog.
	OperationHttpRequest = "request"

	// OperationHttpResponse is the field value used by NewLoggingHTTPTransport
	// and NewSubsystemLoggingHTTPTransport when logging an HTTP response via tflog.
	OperationHttpResponse = "response"

	// FieldHttpRequestMethod is the field key used by NewLoggingHTTPTransport
	// and NewSubsystemLoggingHTTPTransport when logging an HTTP request method via tflog.
	FieldHttpRequestMethod = "tf_http_req_method"

	// FieldHttpRequestUri is the field key used by NewLoggingHTTPTransport
	// and NewSubsystemLoggingHTTPTransport when logging an HTTP request URI via tflog.
	FieldHttpRequestUri = "tf_http_req_uri"

	// FieldHttpRequestProtoVersion is the field key used by NewLoggingHTTPTransport
	// and NewSubsystemLoggingHTTPTransport when logging an HTTP request HTTP version via tflog.
	FieldHttpRequestProtoVersion = "tf_http_req_version"

	// FieldHttpRequestBody is the field key used by NewLoggingHTTPTransport
	// and NewSubsystemLoggingHTTPTransport when logging an HTTP request body via tflog.
	FieldHttpRequestBody = "tf_http_req_body"

	// FieldHttpResponseProtoVersion is the field key used by NewLoggingHTTPTransport
	// and NewSubsystemLoggingHTTPTransport when logging an HTTP response protocol version via tflog.
	FieldHttpResponseProtoVersion = "tf_http_res_version"

	// FieldHttpResponseStatusCode is the field key used by NewLoggingHTTPTransport
	// and NewSubsystemLoggingHTTPTransport when logging an HTTP response status code via tflog.
	FieldHttpResponseStatusCode = "tf_http_res_status_code"

	// FieldHttpResponseStatusReason is the field key used by NewLoggingHTTPTransport
	// and NewSubsystemLoggingHTTPTransport when logging an HTTP response status reason phrase via tflog.
	FieldHttpResponseStatusReason = "tf_http_res_status_reason"

	// FieldHttpResponseBody is the field key used by NewLoggingHTTPTransport
	// and NewSubsystemLoggingHTTPTransport when logging an HTTP response body via tflog.
	FieldHttpResponseBody = "tf_http_res_body"

	// FieldHttpTransactionId is the field key used by NewLoggingHTTPTransport
	// and NewSubsystemLoggingHTTPTransport when logging an HTTP transaction via tflog.
	FieldHttpTransactionId = "tf_http_trans_id"
)

Variables

View Source
var ValidLevels = []logutils.LogLevel{"TRACE", "DEBUG", "INFO", "WARN", "ERROR"}

Functions

func IsDebugOrHigher

func IsDebugOrHigher() bool

IsDebugOrHigher returns whether or not the current log level is debug or trace

func LogLevel

func LogLevel() string

LogLevel returns the current log level string based the environment vars

func LogOutput

func LogOutput(t testing.T) (logOutput io.Writer, err error)

LogOutput determines where we should send logs (if anywhere) and the log level. This only effects this log.Print* functions called in the provider under test. Dependency providers for the provider under test will have their logging controlled by Terraform itself and managed with the TF_ACC_LOG_PATH environment variable. Calls to tflog.* will have their output managed by the tfsdklog sink.

func NewLoggingHTTPTransport added in v2.20.0

func NewLoggingHTTPTransport(t http.RoundTripper) *loggingHttpTransport

NewLoggingHTTPTransport creates a wrapper around an *http.RoundTripper, designed to be used for the `Transport` field of http.Client.

This logs each pair of HTTP request/response that it handles. The logging is done via `tflog`, that is part of the terraform-plugin-log library, included by this SDK.

The request/response is logged via tflog.Debug, using the context.Context attached to the http.Request that the transport receives as input of http.RoundTripper RoundTrip method.

It's responsibility of the developer using this transport, to ensure that each http.Request it handles is configured with the SDK-initialized Provider Root Logger context.Context, that it's passed to all resources/data-sources/provider entry-points (i.e. schema.Resource fields like `CreateContext`, `ReadContext`, etc.).

This also gives the developer the flexibility to further configure the logging behaviour via the above-mentioned context: please see https://www.terraform.io/plugin/log/writing.

func NewSubsystemLoggingHTTPTransport added in v2.20.0

func NewSubsystemLoggingHTTPTransport(subsystem string, t http.RoundTripper) *loggingHttpTransport

NewSubsystemLoggingHTTPTransport creates a wrapper around an *http.RoundTripper, designed to be used for the `Transport` field of http.Client.

This logs each pair of HTTP request/response that it handles. The logging is done via `tflog`, that is part of the terraform-plugin-log library, included by this SDK.

The request/response is logged via tflog.SubsystemDebug, using the context.Context attached to the http.Request that the transport receives as input of http.RoundTripper RoundTrip method, as well as the `subsystem` string provided at construction time.

It's responsibility of the developer using this transport, to ensure that each http.Request it handles is configured with a Subsystem Logger context.Context that was initialized via tflog.NewSubsystem.

This also gives the developer the flexibility to further configure the logging behaviour via the above-mentioned context: please see https://www.terraform.io/plugin/log/writing.

Please note: setting `subsystem` to an empty string it's equivalent to using NewLoggingHTTPTransport.

func NewTransport deprecated

func NewTransport(name string, t http.RoundTripper) *transport

NewTransport creates a wrapper around a *http.RoundTripper, designed to be used for the `Transport` field of http.Client.

This logs each pair of HTTP request/response that it handles. The logging is done via Go standard library `log` package.

Deprecated: This will log the content of every http request/response at `[DEBUG]` level, without any filtering. Any sensitive information will appear as-is in your logs. Please use NewSubsystemLoggingHTTPTransport instead.

func SetOutput

func SetOutput(t testing.T)

SetOutput checks for a log destination with LogOutput, and calls log.SetOutput with the result. If LogOutput returns nil, SetOutput uses io.Discard. Any error from LogOutout is fatal.

Types

This section is empty.

Jump to

Keyboard shortcuts

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