Go DebugGo 程序调试工具
go-debug 是一个用于条件调试日志记录(Conditional debug logging)的 Go 语言库。
示例代码:
代码示例
package main import . "github.com/tj/go-debug" import "time" var debug = Debug("single") func main() { for { debug("sending mail") debug("send email to %s", "tobi@segment.io") debug("send email to %s", "loki@segment.io") debug("send email to %s", "jane@segment.io") time.Sleep(500 * time.Millisecond) } }
如果使用 DEBUG=*
环境变量运行程序,将看到:
15:58:15.115 34us 33us single - sending mail 15:58:15.116 3us 3us single - send email to tobi@segment.io 15:58:15.116 1us 1us single - send email to loki@segment.io 15:58:15.116 1us 1us single - send email to jane@segment.io 15:58:15.620 504ms 504ms single - sending mail 15:58:15.620 6us 6us single - send email to tobi@segment.io 15:58:15.620 4us 4us single - send email to loki@segment.io 15:58:15.620 4us 4us single - send email to jane@segment.io 15:58:16.123 503ms 503ms single - sending mail 15:58:16.123 7us 7us single - send email to tobi@segment.io 15:58:16.123 4us 4us single - send email to loki@segment.io 15:58:16.123 4us 4us single - send email to jane@segment.io 15:58:16.625 501ms 501ms single - sending mail 15:58:16.625 4us 4us single - send email to tobi@segment.io 15:58:16.625 4us 4us single - send email to loki@segment.io 15:58:16.625 5us 5us single - send email to jane@segment.io
评论