英文:
Golang microseconds in log package
问题
Golang有标准的日志包。
有没有办法在其输出中添加微秒?
标准代码会输出带有秒精度的相当无用的时间戳:
log.Println("Starting app on", APP_PORT)
2015/07/29 19:28:32 Starting app on :9090
英文:
Golang have standard log package.
Is there a way to put mircoseconds to its output?
Standard code puts pretty useless timestamp with second precision:
log.Println("Starting app on", APP_PORT)
2015/07/29 19:28:32 Starting app on :9090
答案1
得分: 44
将日志标志更改为添加微秒。可用的标志在这里:http://golang.org/pkg/log/#pkg-constants
log.SetFlags(log.LstdFlags | log.Lmicroseconds)
log.Print("Hello, playground")
// 2009/11/10 23:00:00.000000 Hello, playground
英文:
Change the log flags to add microseconds. Available flags are there: http://golang.org/pkg/log/#pkg-constants
log.SetFlags(log.LstdFlags | log.Lmicroseconds)
log.Print("Hello, playground")
// 2009/11/10 23:00:00.000000 Hello, playground
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论