-
Notifications
You must be signed in to change notification settings - Fork 0
/
target.go
35 lines (29 loc) · 832 Bytes
/
target.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 blackbox
import "sync"
// Target is an interface ment to be implemented by types that collect log
// data. blackbox ships with two of these: PrettyTarget and JSONTarget
type Target interface {
Log(level Level, values []interface{}, context Ctx)
}
type targetSet struct {
targets []Target
targetsLock sync.Mutex
}
func (t *targetSet) log(level Level, values []interface{}, context Ctx) {
for index, value := range values {
if ctx, ok := value.(Ctx); ok {
context = context.Extend(ctx)
values = append(values[:index], values[index+1:]...)
}
}
t.targetsLock.Lock()
for _, target := range t.targets {
target.Log(level, values, context)
}
t.targetsLock.Unlock()
}
func (t *targetSet) addTarget(target Target) {
t.targetsLock.Lock()
t.targets = append(t.targets, target)
t.targetsLock.Unlock()
}