forked from driskell/logstash-forwarder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
codec_plain.go
61 lines (51 loc) · 1.33 KB
/
codec_plain.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
package main
import (
"errors"
"fmt"
)
type CodecPlainRegistrar struct {
}
type CodecPlainFactory struct {
}
type CodecPlain struct {
path string
fileconfig *FileConfig
info *ProspectorInfo
last_offset int64
output chan<- *FileEvent
}
func (r *CodecPlainRegistrar) NewFactory(config map[string]interface{}) (CodecFactory, error) {
for key := range config {
if key == "name" {
} else {
return nil, errors.New(fmt.Sprintf("Invalid property for plain codec, '%s'.", key))
}
}
return &CodecPlainFactory{}, nil
}
func (f *CodecPlainFactory) NewCodec(path string, fileconfig *FileConfig, info *ProspectorInfo, offset int64, output chan<- *FileEvent) Codec {
return &CodecPlain{
path: path,
fileconfig: fileconfig,
info: info,
last_offset: offset,
output: output,
}
}
func (c *CodecPlain) Teardown() int64 {
return c.last_offset
}
func (c *CodecPlain) Event(start_offset int64, end_offset int64, line uint64, text *string) {
c.last_offset = end_offset
// Ship downstream
c.output <- &FileEvent{
ProspectorInfo: c.info,
Offset: end_offset,
Event: NewEvent(c.fileconfig.Fields, &c.path, start_offset, line, text),
}
}
// Register the codec as default
func init() {
RegisterCodec(&CodecPlainRegistrar{}, "")
RegisterCodec(&CodecPlainRegistrar{}, "plain")
}