-
Notifications
You must be signed in to change notification settings - Fork 187
/
output.go
85 lines (73 loc) · 1.48 KB
/
output.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package syslog
import (
"reflect"
scope_manager "github.com/eolinker/apinto/scope-manager"
"github.com/eolinker/apinto/drivers"
"github.com/eolinker/apinto/output"
"github.com/eolinker/eosc"
)
var _ output.IEntryOutput = (*Output)(nil)
var _ eosc.IWorker = (*Output)(nil)
type Output struct {
drivers.WorkerBase
config *Config
writer *SysWriter
running bool
}
func (s *Output) Output(entry eosc.IEntry) error {
w := s.writer
if w != nil {
return w.output(entry)
}
return eosc.ErrorWorkerNotRunning
}
func (s *Output) Start() error {
scope_manager.Del(s.Id())
s.running = true
w := s.writer
if w == nil {
writer, err := CreateTransporter(s.config)
if err != nil {
return err
}
s.writer = writer
}
scope_manager.Set(s.Id(), s, s.config.Scopes...)
return nil
}
func (s *Output) Reset(conf interface{}, workers map[eosc.RequireId]eosc.IWorker) error {
cfg, err := check(conf)
if err != nil {
return err
}
// 新建formatter
if reflect.DeepEqual(cfg, s.config) {
return nil
}
s.config = cfg
if s.running {
if s.writer == nil {
s.writer, err = CreateTransporter(s.config)
if err != nil {
return err
}
}
err = s.writer.reset(cfg)
if err != nil {
return err
}
}
scope_manager.Set(s.Id(), s, s.config.Scopes...)
return nil
}
func (s *Output) Stop() error {
w := s.writer
scope_manager.Del(s.Id())
if w != nil {
return w.stop()
}
return nil
}
func (s *Output) CheckSkill(skill string) bool {
return output.CheckSkill(skill)
}