github.com/mmcquillan/packer@v1.1.1-0.20171009221028-c85cf0483a5d/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 = "PACKER_LOG" //Set to True 11 const EnvLogFile = "PACKER_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) != "" && os.Getenv(EnvLog) != "0" { 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 }