github.com/sc0rp1us/gb@v0.4.1-0.20160319180011-4ba8cf1baa5a/debug/debug.go (about) 1 // debug provides a light weight debug facility. 2 // Usage is via the DEBUG environment variable. Any non empty value will 3 // enable debug logging. For example 4 // 5 // DEBUG=. gb 6 // 7 // The period is a hint that the value passed to DEBUG is a regex, which matches 8 // files, or packages present in the file part of the file/line pair logged as a 9 // prefix of the log line. (not implemented yet) 10 // 11 // Debug output is send to os.Stderr, there is no facility to change this. 12 package debug 13 14 import ( 15 "fmt" 16 "log" 17 "os" 18 ) 19 20 var debug = os.Getenv("DEBUG") 21 22 var logger = log.New(os.Stderr, "", log.Ldate|log.Ltime|log.Lshortfile) 23 24 func Debugf(format string, args ...interface{}) { 25 if len(debug) == 0 { 26 return 27 } 28 logger.Output(2, fmt.Sprintf(format, args...)) 29 }