-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.go
53 lines (48 loc) · 949 Bytes
/
utils.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package zlogtime
import (
"time"
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
)
func getTimeDuration(timeDuration time.Duration, unit string) int64 {
switch unit {
case "nano": // 10e-9
return timeDuration.Nanoseconds()
case "micro": // 10e-6
return timeDuration.Microseconds()
case "milli": // 10e-3
return timeDuration.Milliseconds()
default:
return 0
}
}
func getShortDurationUnit(unit string) string {
switch unit {
case "nano": // 10e-9
return "ns"
case "micro": // 10e-6
return "us"
case "milli": // 10e-3
return "ms"
default:
return ""
}
}
func getLogLevel(level string) *zerolog.Event {
switch level {
case "debug":
return log.Logger.Debug()
case "info":
return log.Logger.Info()
case "warn":
return log.Logger.Warn()
case "error":
return log.Logger.Error()
case "fatal":
return log.Logger.Fatal()
case "panic":
return log.Logger.Panic()
default:
return log.Logger.Log()
}
}