Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Golang microseconds in log package

Tags:

logging

go

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
like image 371
rootatdarkstar Avatar asked Jul 29 '15 17:07

rootatdarkstar


1 Answers

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
like image 199
Alex Netkachov Avatar answered Oct 21 '22 18:10

Alex Netkachov