Movatterモバイル変換


[0]ホーム

URL:


logging

package
v2.38.1Latest Latest
Warning

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

Go to latest
Published: Sep 22, 2025 License:MPL-2.0Imports:18Imported by:150

Details

Repository

github.com/hashicorp/terraform-plugin-sdk

Links

Documentation

Index

Constants

View Source
const (EnvLog        = "TF_LOG"// See ValidLevelsEnvLogFile    = "TF_LOG_PATH"// Set to a fileEnvAccLogFile = "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 ifwe 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

funcIsDebugOrHigher

func IsDebugOrHigher()bool

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

funcLogLevel

func LogLevel()string

LogLevel returns the current log level string based the environment vars

funcLogOutput

func LogOutput(ttesting.T) (logOutputio.Writer, errerror)

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

funcNewLoggingHTTPTransportadded inv2.20.0

func NewLoggingHTTPTransport(thttp.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-loglibrary, included by this SDK.

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

It's responsibility of the developer using this transport, to ensure that eachhttp.Request it handles is configured with the SDK-initialized Provider Root Loggercontext.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 thelogging behaviour via the above-mentioned context: please seehttps://www.terraform.io/plugin/log/writing.

funcNewSubsystemLoggingHTTPTransportadded inv2.20.0

func NewSubsystemLoggingHTTPTransport(subsystemstring, thttp.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-loglibrary, included by this SDK.

The request/response is logged via tflog.SubsystemDebug, using the context.Contextattached to the http.Request that the transport receives as inputof http.RoundTripper RoundTrip method, as well as the `subsystem` stringprovided at construction time.

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

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

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

funcNewTransportdeprecated

func NewTransport(namestring, thttp.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/responseat `[DEBUG]` level, without any filtering. Any sensitive informationwill appear as-is in your logs. Please use NewSubsystemLoggingHTTPTransport instead.

funcSetOutput

func SetOutput(ttesting.T)

SetOutput checks for a log destination with LogOutput, and callslog.SetOutput with the result. If LogOutput returns nil, SetOutput usesio.Discard. Any error from LogOutput is fatal.

Types

This section is empty.

Source Files

View all Source files

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f orF : Jump to
y orY : Canonical URL
go.dev uses cookies from Google to deliver and enhance the quality of its services and to analyze traffic.Learn more.

[8]ページ先頭

©2009-2025 Movatter.jp