forked from influxdata/kapacitor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
log.go
58 lines (53 loc) · 1.23 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
55
56
57
58
package kapacitor
import (
"fmt"
"log"
"strings"
"github.com/influxdata/kapacitor/pipeline"
"github.com/influxdata/wlog"
)
type LogNode struct {
node
level wlog.Level
prefix string
}
// Create a new LogNode which logs all data it receives
func newLogNode(et *ExecutingTask, n *pipeline.LogNode, l *log.Logger) (*LogNode, error) {
level, ok := wlog.StringToLevel[strings.ToUpper(n.Level)]
if !ok {
return nil, fmt.Errorf("invalid log level %s", n.Level)
}
nn := &LogNode{
node: node{Node: n, et: et, logger: l},
level: level,
prefix: n.Prefix,
}
nn.node.runF = nn.runLog
return nn, nil
}
func (s *LogNode) runLog([]byte) error {
key := fmt.Sprintf("%c! %s", wlog.ReverseLevels[s.level], s.prefix)
switch s.Wants() {
case pipeline.StreamEdge:
for p, ok := s.ins[0].NextPoint(); ok; p, ok = s.ins[0].NextPoint() {
s.logger.Println(key, p)
for _, child := range s.outs {
err := child.CollectPoint(p)
if err != nil {
return err
}
}
}
case pipeline.BatchEdge:
for b, ok := s.ins[0].NextBatch(); ok; b, ok = s.ins[0].NextBatch() {
s.logger.Println(key, b)
for _, child := range s.outs {
err := child.CollectBatch(b)
if err != nil {
return err
}
}
}
}
return nil
}