github.com/adamar/terraform@v0.2.2-0.20141016210445-2e703afdad0e/log.go (about)

     1  package main
     2  
     3  import (
     4  	"io"
     5  	"os"
     6  )
     7  
     8  // These are the environmental variables that determine if we log, and if
     9  // we log whether or not the log should go to a file.
    10  const EnvLog = "TF_LOG"          //Set to True
    11  const EnvLogFile = "TF_LOG_PATH" //Set to a file
    12  
    13  // logOutput determines where we should send logs (if anywhere).
    14  func logOutput() (logOutput io.Writer, err error) {
    15  	logOutput = nil
    16  	if os.Getenv(EnvLog) != "" {
    17  		logOutput = os.Stderr
    18  
    19  		if logPath := os.Getenv(EnvLogFile); logPath != "" {
    20  			var err error
    21  			logOutput, err = os.Create(logPath)
    22  			if err != nil {
    23  				return nil, err
    24  			}
    25  		}
    26  	}
    27  
    28  	return
    29  }