-
Notifications
You must be signed in to change notification settings - Fork 1
/
event.go
67 lines (55 loc) · 1.62 KB
/
event.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package recording
import (
log "github.com/echocat/slf4g"
"github.com/echocat/slf4g/fields"
"github.com/echocat/slf4g/level"
)
type event struct {
provider log.Provider
fields fields.Fields
level level.Level
}
func (instance *event) ForEach(consumer func(key string, value interface{}) error) error {
return instance.fields.ForEach(consumer)
}
func (instance *event) Get(key string) (interface{}, bool) {
return instance.fields.Get(key)
}
func (instance *event) Len() int {
return instance.fields.Len()
}
func (instance *event) GetLevel() level.Level {
return instance.level
}
func (instance *event) With(key string, value interface{}) log.Event {
return instance.with(func(s fields.Fields) fields.Fields {
return s.With(key, value)
})
}
func (instance *event) Withf(key string, format string, args ...interface{}) log.Event {
return instance.with(func(s fields.Fields) fields.Fields {
return s.Withf(key, format, args...)
})
}
func (instance *event) WithError(err error) log.Event {
return instance.with(func(s fields.Fields) fields.Fields {
return s.With(instance.provider.GetFieldKeysSpec().GetError(), err)
})
}
func (instance *event) WithAll(of map[string]interface{}) log.Event {
return instance.with(func(s fields.Fields) fields.Fields {
return s.WithAll(of)
})
}
func (instance *event) Without(keys ...string) log.Event {
return instance.with(func(s fields.Fields) fields.Fields {
return s.Without(keys...)
})
}
func (instance *event) with(mod func(fields.Fields) fields.Fields) log.Event {
return &event{
provider: instance.provider,
fields: mod(instance.fields),
level: instance.level,
}
}