2014-05-31 01:07:26 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"io"
|
|
|
|
"os"
|
|
|
|
)
|
|
|
|
|
|
|
|
// These are the environmental variables that determine if we log, and if
|
|
|
|
// we log whether or not the log should go to a file.
|
2014-10-10 23:50:35 +02:00
|
|
|
const EnvLog = "TF_LOG" //Set to True
|
2014-10-01 07:33:59 +02:00
|
|
|
const EnvLogFile = "TF_LOG_PATH" //Set to a file
|
2014-05-31 01:07:26 +02:00
|
|
|
|
|
|
|
// logOutput determines where we should send logs (if anywhere).
|
|
|
|
func logOutput() (logOutput io.Writer, err error) {
|
|
|
|
logOutput = nil
|
|
|
|
if os.Getenv(EnvLog) != "" {
|
|
|
|
logOutput = os.Stderr
|
|
|
|
|
|
|
|
if logPath := os.Getenv(EnvLogFile); logPath != "" {
|
|
|
|
var err error
|
|
|
|
logOutput, err = os.Create(logPath)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|