Skip to content
This repository has been archived by the owner on May 21, 2024. It is now read-only.

Commit

Permalink
New: Generic best effort option for syslog parsers
Browse files Browse the repository at this point in the history
  • Loading branch information
leodido committed Dec 18, 2018
1 parent 2bd793e commit 305b727
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
12 changes: 11 additions & 1 deletion options.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
package syslog

// WithListener returns a generic option for syslog parsers.
// WithListener returns a generic option that sets the emit function for syslog parsers.
func WithListener(f ParserListener) ParserOption {
return func(p Parser) Parser {
p.WithListener(f)
return p
}
}

// WithBestEffort returns a generic options that enables best effort mode for syslog parsers.
//
// When passed to a parser it tries to recover as much of the syslog messages as possible.
func WithBestEffort() ParserOption {
return func(p Parser) Parser {
p.WithBestEffort()
return p
}
}
2 changes: 2 additions & 0 deletions syslog.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@ type MachineOption func(m Machine) Machine

// BestEfforter is an interface that wraps the HasBestEffort method.
type BestEfforter interface {
WithBestEffort()
HasBestEffort() bool
}

// Parser is an interface that wraps the Parse method.
type Parser interface {
Parse(r io.Reader)
WithListener(ParserListener)
BestEfforter
}

// ParserOption represent an option for Parser instances.
Expand Down

0 comments on commit 305b727

Please sign in to comment.