Skip to content

Commit

Permalink
feat: introduce WithMachineOptions() options + remove WithBestEffort(…
Browse files Browse the repository at this point in the history
…) (delegating it to the underlying machine and their options)

Signed-off-by: Leonardo Di Donato <leodidonato@gmail.com>
  • Loading branch information
leodido committed Jan 25, 2025
1 parent 46afcec commit ca1f516
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
15 changes: 7 additions & 8 deletions options.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,19 @@ func WithListener(f ParserListener) ParserOption {
}
}

// 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 {

// WithMaxMessageLength sets the length of the buffer for octect parsing.
func WithMaxMessageLength(length int) ParserOption {
return func(p Parser) Parser {
p.WithBestEffort()
p.WithMaxMessageLength(length)
return p
}
}

// WithMaxMessageLength sets the length of the buffer for octect parsing.
func WithMaxMessageLength(length int) ParserOption {
// WithMachineOptions returns a generic option that sets the machine options for syslog parsers.
func WithMachineOptions(opts ...MachineOption) ParserOption {
return func(p Parser) Parser {
p.WithMaxMessageLength(length)
p.WithMachineOptions(opts...)
return p
}
}
8 changes: 6 additions & 2 deletions syslog.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@ import (
"github.com/leodido/go-syslog/v4/common"
)

// BestEfforter is an interface that wraps the HasBestEffort method.
// BestEfforter is an interface that wraps the WithBestEffort and the HasBestEffort methods.
type BestEfforter interface {
// WithBestEffort enables best effort mode for syslog parsers.
//
// When passed to a parser it tries to recover as much of the syslog messages as possible.
WithBestEffort()
HasBestEffort() bool
}
Expand All @@ -33,7 +36,8 @@ type MachineOption func(m Machine) Machine
type Parser interface {
Parse(r io.Reader)
WithListener(ParserListener)
BestEfforter
WithMachineOptions(opts ...MachineOption)
// BestEfforter
MaxMessager
}

Expand Down

0 comments on commit ca1f516

Please sign in to comment.