rootatdarkstar
rootatdarkstar

Reputation: 1526

Golang microseconds in log package

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

Upvotes: 19

Views: 9942

Answers (1)

Alex Netkachov
Alex Netkachov

Reputation: 13562

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

Upvotes: 47

Related Questions