github.com/bhameyie/otto@v0.2.1-0.20160406174117-16052efa52ec/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 = "OTTO_LOG" //Set to True 11 const EnvLogFile = "OTTOLOG_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 }