#tf-log-levels-and-usage
What is TF_LOG, and which levels make sense to use?
Что отвечать
`TF_LOG` is the env variable for Terraform diagnostics during a command. The levels are TRACE > DEBUG > INFO > WARN > ERROR. TRACE dumps every HTTP operation of the provider, millions of lines. DEBUG is a bit quieter and is usually enough to see what Terraform was trying to do. INFO is the standard production level. For long-running commands, `TF_LOG_PATH=tf.log` writes to a file instead of flooding the terminal. A handy trick: `TF_LOG_PROVIDER=DEBUG` separate from core shows only the provider logs without the graph internals.
Что хотят услышать
A senior should: - separate TF_LOG (everything) from TF_LOG_PROVIDER (provider only); often you only need the second - name `TF_LOG_PATH` for file output; the terminal log loses its scrollback on large states - say that TRACE gives raw HTTP requests and responses to the provider, which is invaluable for diagnosing auth or a timeout - mention that secrets can settle into the logs (Bearer tokens in Authorization headers), so do not share the files without cleaning them
Подводные камни
- ✗ Running `TF_LOG=TRACE plan` without `TF_LOG_PATH`. The terminal floods, and scrolling up to the useful part takes forever
- ✗ Sharing tf.log in Slack without editing it. It has Authorization headers and sometimes excerpts of state
- ✗ Using TF_LOG=INFO when DEBUG is what you need. INFO shows almost nothing, and turning it up costs you nothing
Follow-up
- ? How does `TF_LOG_PROVIDER` differ from plain `TF_LOG`?
- ? Which log levels make sense to mix?
- ? What can you scrub from a TF_LOG file before sharing it?
Глубина в базе знаний