Documentation ¶
Overview ¶
Example (BestEffortOnLastOne) ¶
results := []syslog.Result{} acc := func(res *syslog.Result) { results = append(results, *res) } r := strings.NewReader("<1>1 - - - - - - -\n<3>1\n") NewParser(syslog.WithBestEffort(), syslog.WithListener(acc)).Parse(r) output(results)
Output: ([]syslog.Result) (len=2) { (syslog.Result) { Message: (*rfc5424.SyslogMessage)({ Base: (syslog.Base) { Facility: (*uint8)(0), Severity: (*uint8)(1), Priority: (*uint8)(1), Timestamp: (*time.Time)(<nil>), Hostname: (*string)(<nil>), Appname: (*string)(<nil>), ProcID: (*string)(<nil>), MsgID: (*string)(<nil>), Message: (*string)((len=1) "-") }, Version: (uint16) 1, StructuredData: (*map[string]map[string]string)(<nil>) }), Error: (error) <nil> }, (syslog.Result) { Message: (*rfc5424.SyslogMessage)({ Base: (syslog.Base) { Facility: (*uint8)(0), Severity: (*uint8)(3), Priority: (*uint8)(3), Timestamp: (*time.Time)(<nil>), Hostname: (*string)(<nil>), Appname: (*string)(<nil>), ProcID: (*string)(<nil>), MsgID: (*string)(<nil>), Message: (*string)(<nil>) }, Version: (uint16) 1, StructuredData: (*map[string]map[string]string)(<nil>) }), Error: (*errors.errorString)(parsing error [col 4]) } }
Example (BestEffortWithoutTrailerAtEnd) ¶
results := []syslog.Result{} acc := func(res *syslog.Result) { results = append(results, *res) } // Notice the message ends without trailer but we catch it anyway r := strings.NewReader("<1>1 2003-10-11T22:14:15.003Z host.local - - - - mex") NewParser(syslog.WithBestEffort(), syslog.WithListener(acc)).Parse(r) output(results)
Output: ([]syslog.Result) (len=1) { (syslog.Result) { Message: (*rfc5424.SyslogMessage)({ Base: (syslog.Base) { Facility: (*uint8)(0), Severity: (*uint8)(1), Priority: (*uint8)(1), Timestamp: (*time.Time)(2003-10-11 22:14:15.003 +0000 UTC), Hostname: (*string)((len=10) "host.local"), Appname: (*string)(<nil>), ProcID: (*string)(<nil>), MsgID: (*string)(<nil>), Message: (*string)((len=3) "mex") }, Version: (uint16) 1, StructuredData: (*map[string]map[string]string)(<nil>) }), Error: (error) <nil> } }
Example (IntoChannelWithLF) ¶
messages := []string{ "<2>1 - - - - - - A\nB", "<1>1 -", "<1>1 - - - - - - A\nB\nC\nD", } r, w := io.Pipe() go func() { defer w.Close() for _, m := range messages { // Write message (containing trailers to be interpreted as part of the syslog MESSAGE) w.Write([]byte(m)) // Write non-transparent frame boundary w.Write([]byte{10}) // Wait a random amount of time time.Sleep(time.Millisecond * time.Duration(rand.Intn(100))) } }() results := make(chan *syslog.Result) ln := func(x *syslog.Result) { // Emit the result results <- x } p := NewParser(syslog.WithListener(ln), syslog.WithBestEffort()) go func() { defer close(results) defer r.Close() p.Parse(r) }() // Consume results for r := range results { output(r) }
Output: (*syslog.Result)({ Message: (*rfc5424.SyslogMessage)({ Base: (syslog.Base) { Facility: (*uint8)(0), Severity: (*uint8)(2), Priority: (*uint8)(2), Timestamp: (*time.Time)(<nil>), Hostname: (*string)(<nil>), Appname: (*string)(<nil>), ProcID: (*string)(<nil>), MsgID: (*string)(<nil>), Message: (*string)((len=3) "A\nB") }, Version: (uint16) 1, StructuredData: (*map[string]map[string]string)(<nil>) }), Error: (error) <nil> }) (*syslog.Result)({ Message: (*rfc5424.SyslogMessage)({ Base: (syslog.Base) { Facility: (*uint8)(0), Severity: (*uint8)(1), Priority: (*uint8)(1), Timestamp: (*time.Time)(<nil>), Hostname: (*string)(<nil>), Appname: (*string)(<nil>), ProcID: (*string)(<nil>), MsgID: (*string)(<nil>), Message: (*string)(<nil>) }, Version: (uint16) 1, StructuredData: (*map[string]map[string]string)(<nil>) }), Error: (*errors.errorString)(parsing error [col 6]) }) (*syslog.Result)({ Message: (*rfc5424.SyslogMessage)({ Base: (syslog.Base) { Facility: (*uint8)(0), Severity: (*uint8)(1), Priority: (*uint8)(1), Timestamp: (*time.Time)(<nil>), Hostname: (*string)(<nil>), Appname: (*string)(<nil>), ProcID: (*string)(<nil>), MsgID: (*string)(<nil>), Message: (*string)((len=7) "A\nB\nC\nD") }, Version: (uint16) 1, StructuredData: (*map[string]map[string]string)(<nil>) }), Error: (error) <nil> })
Example (IntoChannelWithNUL) ¶
messages := []string{ "<2>1 - - - - - - A\x00B", "<1>1 -", "<1>1 - - - - - - A\x00B\x00C\x00D", } r, w := io.Pipe() go func() { defer w.Close() for _, m := range messages { // Write message (containing trailers to be interpreted as part of the syslog MESSAGE) w.Write([]byte(m)) // Write non-transparent frame boundary w.Write([]byte{0}) // Wait a random amount of time time.Sleep(time.Millisecond * time.Duration(rand.Intn(100))) } }() results := make(chan *syslog.Result) ln := func(x *syslog.Result) { // Emit the result results <- x } p := NewParser(syslog.WithListener(ln), WithTrailer(NUL)) go func() { defer close(results) defer r.Close() p.Parse(r) }() // Range over the results channel for r := range results { output(r) }
Output: (*syslog.Result)({ Message: (*rfc5424.SyslogMessage)({ Base: (syslog.Base) { Facility: (*uint8)(0), Severity: (*uint8)(2), Priority: (*uint8)(2), Timestamp: (*time.Time)(<nil>), Hostname: (*string)(<nil>), Appname: (*string)(<nil>), ProcID: (*string)(<nil>), MsgID: (*string)(<nil>), Message: (*string)((len=3) "A\x00B") }, Version: (uint16) 1, StructuredData: (*map[string]map[string]string)(<nil>) }), Error: (error) <nil> }) (*syslog.Result)({ Message: (syslog.Message) <nil>, Error: (*errors.errorString)(parsing error [col 6]) }) (*syslog.Result)({ Message: (*rfc5424.SyslogMessage)({ Base: (syslog.Base) { Facility: (*uint8)(0), Severity: (*uint8)(1), Priority: (*uint8)(1), Timestamp: (*time.Time)(<nil>), Hostname: (*string)(<nil>), Appname: (*string)(<nil>), ProcID: (*string)(<nil>), MsgID: (*string)(<nil>), Message: (*string)((len=7) "A\x00B\x00C\x00D") }, Version: (uint16) 1, StructuredData: (*map[string]map[string]string)(<nil>) }), Error: (error) <nil> })
Example (WithoutTrailerAtEnd) ¶
results := []syslog.Result{} acc := func(res *syslog.Result) { results = append(results, *res) } // Notice the message ends without trailer but we catch it anyway r := strings.NewReader("<1>1 2003-10-11T22:14:15.003Z host.local - - - - mex") NewParser(syslog.WithListener(acc)).Parse(r) output(results)
Output: ([]syslog.Result) (len=1) { (syslog.Result) { Message: (syslog.Message) <nil>, Error: (*ragel.ReadingError)(unexpected EOF) } }
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewParser ¶
func NewParser(options ...syslog.ParserOption) syslog.Parser
NewParser returns a syslog.Parser suitable to parse syslog messages sent with non-transparent framing - ie. RFC 6587.
func NewParserRFC3164 ¶ added in v4.1.0
func NewParserRFC3164(options ...syslog.ParserOption) syslog.Parser
func WithTrailer ¶
func WithTrailer(t TrailerType) syslog.ParserOption
WithTrailer ... todo(leodido)
Types ¶
type TrailerType ¶
type TrailerType int
TrailerType is the king of supported trailers for non-transparent frames.
const ( // LF is the line feed - ie., byte 10. Also the default one. LF TrailerType = iota // NUL is the nul byte - ie., byte 0. NUL )
func TrailerTypeFromString ¶
func TrailerTypeFromString(s string) (TrailerType, error)
TrailerTypeFromString returns a TrailerType given a string.
func (TrailerType) MarshalText ¶
func (t TrailerType) MarshalText() ([]byte, error)
MarshalText implements encoding.TextMarshaler
func (TrailerType) String ¶
func (t TrailerType) String() string
func (*TrailerType) UnmarshalTOML ¶
func (t *TrailerType) UnmarshalTOML(data []byte) (err error)
UnmarshalTOML decodes trailer type from TOML data.
func (*TrailerType) UnmarshalText ¶
func (t *TrailerType) UnmarshalText(data []byte) (err error)
UnmarshalText implements encoding.TextUnmarshaler
func (TrailerType) Value ¶
func (t TrailerType) Value() (int, error)
Value returns the byte corresponding to the receiving TrailerType.
Click to show internal directories.
Click to hide internal directories.