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

package rfc3164

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

Code:

i := []byte(`<13>Dec  2 16:31:03 host app: Test`)
p := NewParser()
m, _ := p.Parse(i)
output(m)

Output:

(*rfc3164.SyslogMessage)({
 Base: (syslog.Base) {
  Facility: (*uint8)(1),
  Severity: (*uint8)(5),
  Priority: (*uint8)(13),
  Timestamp: (*time.Time)(0000-12-02 16:31:03 +0000 UTC),
  Hostname: (*string)((len=4) "host"),
  Appname: (*string)((len=3) "app"),
  ProcID: (*string)(<nil>),
  MsgID: (*string)(<nil>),
  Message: (*string)((len=4) "Test")
 }
})

Code:

i := []byte(`<13>Dec  2 16:31:03 -`)
p := NewParser(WithBestEffort())
m, _ := p.Parse(i)
output(m)

Output:

(*rfc3164.SyslogMessage)({
 Base: (syslog.Base) {
  Facility: (*uint8)(1),
  Severity: (*uint8)(5),
  Priority: (*uint8)(13),
  Timestamp: (*time.Time)(0000-12-02 16:31:03 +0000 UTC),
  Hostname: (*string)(<nil>),
  Appname: (*string)(<nil>),
  ProcID: (*string)(<nil>),
  MsgID: (*string)(<nil>),
  Message: (*string)(<nil>)
 }
})

Code:

i := []byte(`<13>Dec  2 16:31:03 host app: Test`)
p := NewParser(WithYear(CurrentYear{}))
m, _ := p.Parse(i)
output(m)

Output:

(*rfc3164.SyslogMessage)({
 Base: (syslog.Base) {
  Facility: (*uint8)(1),
  Severity: (*uint8)(5),
  Priority: (*uint8)(13),
  Timestamp: (*time.Time)(2020-12-02 16:31:03 +0000 UTC),
  Hostname: (*string)((len=4) "host"),
  Appname: (*string)((len=3) "app"),
  ProcID: (*string)(<nil>),
  MsgID: (*string)(<nil>),
  Message: (*string)((len=4) "Test")
 }
})

Code:

i := []byte(`<28>2019-12-02T16:49:23+02:00 host app[23410]: Test`)
p := NewParser(WithRFC3339())
m, _ := p.Parse(i)
output(m)

Output:

(*rfc3164.SyslogMessage)({
 Base: (syslog.Base) {
  Facility: (*uint8)(3),
  Severity: (*uint8)(4),
  Priority: (*uint8)(28),
  Timestamp: (*time.Time)(2019-12-02 16:49:23 +0200 +0200),
  Hostname: (*string)((len=4) "host"),
  Appname: (*string)((len=3) "app"),
  ProcID: (*string)((len=5) "23410"),
  MsgID: (*string)(<nil>),
  Message: (*string)((len=4) "Test")
 }
})

Code:

pst, _ := time.LoadLocation("America/New_York")
i := []byte(`<13>Nov 22 17:09:42 xxx kernel: [118479565.921459] EXT4-fs warning (device sda8): ext4_dx_add_entry:2006: Directory index full!`)
p := NewParser(WithLocaleTimezone(pst))
m, _ := p.Parse(i)
output(m)

Output:

(*rfc3164.SyslogMessage)({
 Base: (syslog.Base) {
  Facility: (*uint8)(1),
  Severity: (*uint8)(5),
  Priority: (*uint8)(13),
  Timestamp: (*time.Time)(0000-11-22 17:09:42 -0456 LMT),
  Hostname: (*string)((len=3) "xxx"),
  Appname: (*string)((len=6) "kernel"),
  ProcID: (*string)(<nil>),
  MsgID: (*string)(<nil>),
  Message: (*string)((len=95) "[118479565.921459] EXT4-fs warning (device sda8): ext4_dx_add_entry:2006: Directory index full!")
 }
})

Code:

cet, _ := time.LoadLocation("CET")
i := []byte(`<13>Jan 30 02:08:03 host app: Test`)
p := NewParser(WithTimezone(cet))
m, _ := p.Parse(i)
output(m)

Output:

(*rfc3164.SyslogMessage)({
 Base: (syslog.Base) {
  Facility: (*uint8)(1),
  Severity: (*uint8)(5),
  Priority: (*uint8)(13),
  Timestamp: (*time.Time)(0000-01-30 03:08:03 +0100 CET),
  Hostname: (*string)((len=4) "host"),
  Appname: (*string)((len=3) "app"),
  ProcID: (*string)(<nil>),
  MsgID: (*string)(<nil>),
  Message: (*string)((len=4) "Test")
 }
})

Index

Examples

Package Files

machine.go options.go parser.go syslog_message.go year.go

func NewMachine Uses

func NewMachine(options ...syslog.MachineOption) syslog.Machine

NewMachine creates a new FSM able to parse RFC3164 syslog messages.

func NewParser Uses

func NewParser(options ...syslog.MachineOption) syslog.Machine

NewParser creates a syslog.Machine that parses RFC3164 syslog messages.

func WithBestEffort Uses

func WithBestEffort() syslog.MachineOption

WithBestEffort enables the best effort mode.

func WithLocaleTimezone Uses

func WithLocaleTimezone(loc *time.Location) syslog.MachineOption

WithLocaleTimezone sets the strategy to decide the timezone to apply to the Stamp timestamp of RFC 3164.

func WithRFC3339 Uses

func WithRFC3339() syslog.MachineOption

WithRFC3339 tells the parser to look for RFC3339 timestamps, too.

It tells the parser to accept also RFC3339 timestamps even if they are not in the RFC3164 timestamp part. Note that WithYear option will be ignored when an RFC3339 timestamp will match.

func WithTimezone Uses

func WithTimezone(loc *time.Location) syslog.MachineOption

WithTimezone sets the strategy to decide the timezone to apply to the Stamp timestamp of RFC 3164.

func WithYear Uses

func WithYear(o YearOperator) syslog.MachineOption

WithYear sets the strategy to decide the year for the Stamp timestamp of RFC 3164.

type CurrentYear Uses

type CurrentYear struct{}

CurrentYear is a strategy to obtain the current year in RFC 3164 syslog messages.

func (CurrentYear) Apply Uses

func (CurrentYear) Apply() int

Apply gets the current year

type SyslogMessage Uses

type SyslogMessage struct {
    syslog.Base
}

SyslogMessage represents a RFC3164 syslog message.

type Year Uses

type Year struct {
    YYYY int
}

Year is a strategy to obtain the specified year in the RFC 3164 syslog messages.

func (Year) Apply Uses

func (y Year) Apply() int

Apply gets the specified year

type YearOperation Uses

type YearOperation struct {
    Operator YearOperator
}

YearOperation represents the operation to perform to obtain the year depending on the inner operator/strategy.

func (YearOperation) Operate Uses

func (y YearOperation) Operate() int

Operate gets the year depending on the current strategy.

type YearOperator Uses

type YearOperator interface {
    Apply() int
}

YearOperator is an interface that the operation inferring the year have to implement.

Package rfc3164 imports 5 packages (graph). Updated 2020-04-21. Refresh now. Tools for package owners.