-
Notifications
You must be signed in to change notification settings - Fork 1
/
teesink.go
57 lines (43 loc) · 1.12 KB
/
teesink.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
package telemetry
import "github.com/go-logr/logr"
type teeSink []logr.LogSink
func TeeSink(sinks ...logr.LogSink) logr.LogSink {
return teeSink(sinks)
}
func (sinks teeSink) Enabled(level int) bool {
for _, sink := range sinks {
if !sink.Enabled(level) {
return false
}
}
return true
}
func (sinks teeSink) Error(err error, msg string, keysAndValues ...interface{}) {
for _, sink := range sinks {
sink.Error(err, msg, keysAndValues...)
}
}
func (sinks teeSink) Info(level int, msg string, keysAndValues ...interface{}) {
for _, sink := range sinks {
sink.Info(level, msg, keysAndValues...)
}
}
func (sinks teeSink) Init(info logr.RuntimeInfo) {
for _, sink := range sinks {
sink.Init(info)
}
}
func (sinks teeSink) WithValues(keysAndValues ...interface{}) logr.LogSink {
newSinks := make(teeSink, len(sinks))
for index, sink := range sinks {
newSinks[index] = sink.WithValues(keysAndValues...)
}
return newSinks
}
func (sinks teeSink) WithName(name string) logr.LogSink {
newSinks := make(teeSink, len(sinks))
for index, sink := range sinks {
newSinks[index] = sink.WithName(name)
}
return newSinks
}