forked from influxdata/go-syslog
-
Notifications
You must be signed in to change notification settings - Fork 1
/
parser.go
45 lines (36 loc) · 900 Bytes
/
parser.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
package rfc3164
import (
"sync"
syslog "github.com/observiq/go-syslog/v3"
)
// parser represent a RFC3164 parser with mutex capabilities.
type parser struct {
sync.Mutex
*machine
}
// NewParser creates a syslog.Machine that parses RFC3164 syslog messages.
func NewParser(options ...syslog.MachineOption) syslog.Machine {
p := &parser{
machine: NewMachine(options...).(*machine),
}
return p
}
// HasBestEffort tells whether the receiving parser has best effort mode on or off.
func (p *parser) HasBestEffort() bool {
return p.bestEffort
}
// Parse parses the input RFC3164 syslog message using its FSM.
//
// Best effort mode enables the partial parsing.
func (p *parser) Parse(input []byte) (syslog.Message, error) {
p.Lock()
defer p.Unlock()
msg, err := p.machine.Parse(input)
if err != nil {
if p.bestEffort {
return msg, err
}
return nil, err
}
return msg, nil
}