-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtimetrack.go
35 lines (29 loc) · 921 Bytes
/
timetrack.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package zlogtime
import (
"strconv"
"time"
)
type ZLogTime interface {
TimeTrack(name string, start time.Time)
}
func (cfg *Config) TimeTrack(name string, start time.Time) {
eventName := "TimeTrack"
if name != "" {
eventName = name
}
logTime := time.Now()
elapsedTime := getTimeDuration(time.Since(start), cfg.ElapsedTimeUnit)
shortUnit := getShortDurationUnit(cfg.ElapsedTimeUnit)
logger := getLogLevel(cfg.LogLevel)
logger = logger.
Interface("event", map[string]interface{}{
"name": eventName,
"start": start.Format(TimeFieldFormat),
"end": logTime.Format(TimeFieldFormat),
"elapsed_time": elapsedTime,
"elapsed_time_unit": cfg.ElapsedTimeUnit,
"elapsed_time_unit_short": shortUnit,
"elapsed_time_string": strconv.FormatInt(elapsedTime, 10) + shortUnit,
})
logger.Msg("TimeTrack at: " + name)
}