»Managing Log Output
Terraform binary, providers, and provider SDKs can all write logs that provide insight into operations and help you diagnose bugs. You can use environment variables to turn on logging, filter log output, choose the log format, and specify the log output path.
- All logs for Terraform binary, providers, and provider SDKs, set
TF_LOG. When you report bugs to issue trackers, we recommend setting
- A subset of logs (e.g., for one provider), set the only the environment variables for your use case.
The following environment variables turn on logging and can help you filter log output. Some environment variables take precedence over others. For example,
TF_LOG overrides all other logging variables. If you set
TF_LOG_PROVIDER_AZUREM=WARN, all providers will write logs at the
|Variable||Logs Written By||Precedence and Usage|
|All loggers (Terraform, SDKs, providers)||Overrides all other logging environment variables.|
|Terraform binary||Does not include providers.|
|All providers and provider SDKs used during the run||Overrides logging environment variables for specific providers (e.g., |
|Specific provider||Only applies to providers that write logs using the |
|All SDKs for providers used during the run||Only applies to logs written with |
|Protocol layer logging for providers built on ||Overrides |
To specify logging verbosity, set a logging environment variable to one of the following values:
OFF- Turns off logging for that logger.
ERROR- Least verbose, typically provides more detail about user-facing errors.
WARN- Typically includes warnings about deprecations or other environment problems.
INFO- Can include details about run environment or configuration.
DEBUG- Can include additional details about behavior, especially behaviors that may be non-intuitive.
TRACE- Most verbose, typically includes low-level execution steps.
Important: Before Terraform v0.15.0, levels besides
TRACE may not be reliable. This pull request has more details.
This example sets the loggers for all providers used in the run to
By default, logs are written as plaintext lines, prefixed with a timestamp and the level in square braces.
YYYY-MM-DDTHH:MM:SS.SSSZ [Level] Message...
Explicitly setting the log format to
JSON will output logs in a machine-readable format at the TRACE logging level. This format is not guaranteed to be stable between releases.
TF_LOG_PATH to specify a file path where the log output file should be written. If you do not specify a log path, Terraform writes the specified log output to
Terraform can automatically create the output file at
TF_LOG_PATH if it does not already exist. If the file does exist, Terraform adds new log output onto the end of the file without truncating the file contents.
Important: Do not write to
stdout because our plugin system uses this as a communication channel.
During testing, Terraform ignores
TF_LOG_CORE, and logging environment variables only control the log output for the provider under test. The one exception is
TF_LOG_PROVIDER. This is because
TF_LOG_PROVIDER only affects logs that are produced through the Terraform CLI, and provider logs are not produced through the CLI during acceptance tests.
Refer to acceptance testing for additional environment variables that help you manage test log output.