This repository has been archived on 2022-09-04. You can view files and clone it, but cannot push or open issues or pull requests.
shared/utils/track_execution_time.go

22 lines
377 B
Go

package utils
import (
"time"
"github.com/sirupsen/logrus"
)
func TrackExecutionTime(log *logrus.Entry, fn func(), fnName string) func() {
return func() {
now := time.Now()
log := log.WithField("fnName", fnName)
log.Infof("%s: called", fnName)
fn()
log.
WithField("executionTime", time.Since(now).String()).
Infof("%s: finished executing", fnName)
}
}