-
Notifications
You must be signed in to change notification settings - Fork 16
/
ninetail.go
65 lines (52 loc) · 890 Bytes
/
ninetail.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
59
60
61
62
63
64
65
package ninetail
import (
"io"
"os"
"sync"
"github.com/mattn/go-colorable"
)
type NineTail struct {
output io.Writer
tailers []*Tailer
}
type Config struct {
Colorize bool
}
func Runner(filenames []string, config Config) (*NineTail, error) {
var output io.Writer
if config.Colorize {
output = colorable.NewColorableStdout()
} else {
output = colorable.NewNonColorable(os.Stdout)
}
tailers, err := NewTailers(filenames)
if err != nil {
return nil, err
}
return &NineTail{
output: output,
tailers: tailers,
}, nil
}
func (n *NineTail) Run() {
var wg sync.WaitGroup
for _, t := range n.tailers {
wg.Add(1)
go func(t *Tailer) {
t.Do(n.output)
wg.Done()
}(t)
}
wg.Wait()
}
func (n *NineTail) Stop() {
var wg sync.WaitGroup
for _, t := range n.tailers {
wg.Add(1)
go func(t *Tailer) {
t.Stop()
wg.Done()
}(t)
}
wg.Wait()
}