forked from influxdata/kapacitor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
log.go
54 lines (44 loc) · 1.02 KB
/
log.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
// +build debug
package edge
import (
"github.com/influxdata/kapacitor/pipeline"
)
type Diagnostic interface {
Collect(mtype MessageType)
Emit(mtype MessageType)
}
type logEdge struct {
e Edge
diag Diagnostic
}
// NewLogEdge creates an edge that logs the type of all collected and emitted messages.
//
// This edge should only be used during debug sessions and not in production code.
// As such by default build tags exclude this file from being compiled.
// Add the `-tags debug` arguments to build or test commands in order to include this file for compilation.
func NewLogEdge(d Diagnostic, e Edge) Edge {
return &logEdge{
e: e,
diag: d,
}
}
func (e *logEdge) Collect(m Message) error {
e.diag.Collect(m.Type())
return e.e.Collect(m)
}
func (e *logEdge) Emit() (m Message, ok bool) {
m, ok = e.e.Emit()
if ok {
e.diag.Emit(m.Type())
}
return
}
func (e *logEdge) Close() error {
return e.e.Close()
}
func (e *logEdge) Abort() {
e.e.Abort()
}
func (e *logEdge) Type() pipeline.EdgeType {
return e.e.Type()
}