Golang日志包中的微秒

huangapple go评论86阅读模式
英文:

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

huangapple
  • 本文由 发表于 2015年7月30日 01:09:29
  • 转载请务必保留本文链接:https://go.coder-hub.com/31706893.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定