go_tab-magic/pkg/utils/logging.go

16 lines
486 B
Go
Raw Normal View History

2019-01-14 18:36:15 +00:00
package utils
import (
"log"
"time"
)
//LogElapsedTime provides a function that can be used to log the time elapsed between when this function is invoked, to the time the returned function is invoked.
//Adding "defer LogElapsedTime("my log")" at the beginning of any function will log the time it takes to execute that function.
func LogElapsedTime(what string) func() {
start := time.Now()
return func() {
log.Printf("%s, Total Time Taken: %v\n", what, time.Since(start))
}
}