-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.go
42 lines (34 loc) · 963 Bytes
/
config.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
package metrics
type SecondsMultiplier float64
const (
LogUnitSeconds = SecondsMultiplier(1.0)
LogUnitMilliseconds = SecondsMultiplier(1.0 / 1000.0)
LogUnitMicroseconds = SecondsMultiplier(1.0 / 1000000.0)
)
type LogFieldValueFunc func(map[string]interface{}) interface{}
func FirstLevelLogField(fieldName string) LogFieldValueFunc {
return func(log map[string]interface{}) interface{} {
return log[fieldName]
}
}
func SecondLevelLogField(firstLevelFieldName, secondLevelFieldName string) LogFieldValueFunc {
return func(log map[string]interface{}) interface{} {
first, ok := log[firstLevelFieldName]
if !ok {
return nil
}
m, ok := first.(map[string]interface{})
if !ok {
return nil
}
return m[secondLevelFieldName]
}
}
type Configuration struct {
RequestTimeLogField LogFieldValueFunc
RequestTimeLogUnit SecondsMultiplier
}
var defaultConfig = &Configuration{}
func Configure(c *Configuration) {
defaultConfig = c
}