Global debug logger; enable by setting environment variable D=t
$ D=t go run main.go
func main() {
debug.Print("hello ...")
}
// debug logger is global to one package
var debug = log.New(ioutil.Discard, "D ", log.LstdFlags|log.Lshortfile)
func init() {
// enable debug log if environment D=t is set
if yes, _ := strconv.ParseBool(os.Getenv("D")); yes {
debug.SetOutput(os.Stderr)
}
}