-
Notifications
You must be signed in to change notification settings - Fork 111
/
tolog.go
37 lines (32 loc) · 881 Bytes
/
tolog.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
package library
import (
"github.com/nytlabs/streamtools/st/blocks" // blocks
)
// specify those channels we're going to use to communicate with streamtools
type ToLog struct {
blocks.Block
in chan interface{}
quit chan interface{}
}
// we need to build a simple factory so that streamtools can make new blocks of this kind
func NewToLog() blocks.BlockInterface {
return &ToLog{}
}
// Setup is called once before running the block. We build up the channels and specify what kind of block this is.
func (b *ToLog) Setup() {
b.Kind = "ToLog"
b.Desc = "quick way to view data in your streams; logs both to STDOUT and the GUI"
b.in = b.InRoute("in")
b.quit = b.Quit()
}
// Run is the block's main loop. Here we listen on the different channels we set up.
func (b *ToLog) Run() {
for {
select {
case <-b.quit:
return
case msg := <-b.in:
b.Log(msg)
}
}
}