go-syslog: github.com/influxdata/go-syslog/octetcounting Index | Examples | Files

package octetcounting

import "github.com/influxdata/go-syslog/octetcounting"

Code:

results := []syslog.Result{}
acc := func(res *syslog.Result) {
    results = append(results, *res)
}
r := strings.NewReader("48 <1>1 2003-10-11T22:14:15.003Z host.local - - - -25 <3>1 - host.local - - - -38 <2>1 - host.local su - - - κόσμε")
NewParser(syslog.WithBestEffort(), syslog.WithListener(acc)).Parse(r)
output(results)

Output:

([]syslog.Result) (len=3) {
 (syslog.Result) {
  Message: (*rfc5424.SyslogMessage)({
   priority: (*uint8)(1),
   facility: (*uint8)(0),
   severity: (*uint8)(1),
   version: (uint16) 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>),
   structuredData: (*map[string]map[string]string)(<nil>),
   message: (*string)(<nil>)
  }),
  Error: (error) <nil>
 },
 (syslog.Result) {
  Message: (*rfc5424.SyslogMessage)({
   priority: (*uint8)(3),
   facility: (*uint8)(0),
   severity: (*uint8)(3),
   version: (uint16) 1,
   timestamp: (*time.Time)(<nil>),
   hostname: (*string)((len=10) "host.local"),
   appname: (*string)(<nil>),
   procID: (*string)(<nil>),
   msgID: (*string)(<nil>),
   structuredData: (*map[string]map[string]string)(<nil>),
   message: (*string)(<nil>)
  }),
  Error: (error) <nil>
 },
 (syslog.Result) {
  Message: (*rfc5424.SyslogMessage)({
   priority: (*uint8)(2),
   facility: (*uint8)(0),
   severity: (*uint8)(2),
   version: (uint16) 1,
   timestamp: (*time.Time)(<nil>),
   hostname: (*string)((len=10) "host.local"),
   appname: (*string)((len=2) "su"),
   procID: (*string)(<nil>),
   msgID: (*string)(<nil>),
   structuredData: (*map[string]map[string]string)(<nil>),
   message: (*string)((len=11) "κόσμε")
  }),
  Error: (error) <nil>
 }
}

Code:

messages := []string{
    "16 <1>1 - - - - - -",
    "17 <2>12 A B C D E -",
    "16 <1>1",
}

r, w := io.Pipe()

go func() {
    defer w.Close()

    for _, m := range messages {
        w.Write([]byte(m))
        time.Sleep(time.Millisecond * 220)
    }
}()

c := make(chan syslog.Result)
emit := func(res *syslog.Result) {
    c <- *res
}

parser := NewParser(syslog.WithBestEffort(), syslog.WithListener(emit))
go func() {
    defer close(c)
    parser.Parse(r)
}()

for r := range c {
    output(r)
}

r.Close()

Output:

(syslog.Result) {
 Message: (*rfc5424.SyslogMessage)({
  priority: (*uint8)(1),
  facility: (*uint8)(0),
  severity: (*uint8)(1),
  version: (uint16) 1,
  timestamp: (*time.Time)(<nil>),
  hostname: (*string)(<nil>),
  appname: (*string)(<nil>),
  procID: (*string)(<nil>),
  msgID: (*string)(<nil>),
  structuredData: (*map[string]map[string]string)(<nil>),
  message: (*string)(<nil>)
 }),
 Error: (error) <nil>
}
(syslog.Result) {
 Message: (*rfc5424.SyslogMessage)({
  priority: (*uint8)(2),
  facility: (*uint8)(0),
  severity: (*uint8)(2),
  version: (uint16) 12,
  timestamp: (*time.Time)(<nil>),
  hostname: (*string)(<nil>),
  appname: (*string)(<nil>),
  procID: (*string)(<nil>),
  msgID: (*string)(<nil>),
  structuredData: (*map[string]map[string]string)(<nil>),
  message: (*string)(<nil>)
 }),
 Error: (*errors.errorString)(expecting a RFC3339MICRO timestamp or a nil value [col 6])
}
(syslog.Result) {
 Message: (*rfc5424.SyslogMessage)({
  priority: (*uint8)(1),
  facility: (*uint8)(0),
  severity: (*uint8)(1),
  version: (uint16) 1,
  timestamp: (*time.Time)(<nil>),
  hostname: (*string)(<nil>),
  appname: (*string)(<nil>),
  procID: (*string)(<nil>),
  msgID: (*string)(<nil>),
  structuredData: (*map[string]map[string]string)(<nil>),
  message: (*string)(<nil>)
 }),
 Error: (*errors.errorString)(parsing error [col 4])
}

Index

Examples

Package Files

parser.go scanner.go tokens.go

func NewParser Uses

func NewParser(opts ...syslog.ParserOption) syslog.Parser

NewParser returns a syslog.Parser suitable to parse syslog messages sent with transparent - ie. octet counting (RFC 5425) - framing.

type Scanner Uses

type Scanner struct {
    // contains filtered or unexported fields
}

Scanner represents the lexical scanner for octet counting transport.

func NewScanner Uses

func NewScanner(r io.Reader) *Scanner

NewScanner returns a pointer to a new instance of Scanner.

func (*Scanner) Scan Uses

func (s *Scanner) Scan() (tok Token)

Scan returns the next token.

type Token Uses

type Token struct {
    // contains filtered or unexported fields
}

Token represents a lexical token of the octetcounting.

func (Token) String Uses

func (t Token) String() string

String outputs the string representation of the receiving Token.

type TokenType Uses

type TokenType int

TokenType represents a lexical token type of the octetcounting.

const (
    ILLEGAL TokenType = iota
    EOF
    WS
    MSGLEN
    SYSLOGMSG
)

Tokens

func (TokenType) String Uses

func (i TokenType) String() string

String outputs the string representation of the receiving TokenType.

Package octetcounting imports 7 packages (graph) and is imported by 3 packages. Updated 2019-09-02. Refresh now. Tools for package owners.