rfc3164

package
v3.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 5, 2020 License: MIT Imports: 5 Imported by: 11

Documentation

Overview

Example
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")
 }
})
Example (Besteffort)
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>)
 }
})
Example (Currentyear)
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")
 }
})
Example (Rfc3339timestamp)
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")
 }
})
Example (Stamp_also_when_rfc3339)
i := []byte(`<28>Dec  2 16:49:23 host app[23410]: Test`)
p := NewParser(WithYear(Year{YYYY: 2019}), 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 +0000 UTC),
  Hostname: (*string)((len=4) "host"),
  Appname: (*string)((len=3) "app"),
  ProcID: (*string)((len=5) "23410"),
  MsgID: (*string)(<nil>),
  Message: (*string)((len=4) "Test")
 }
})
Example (Withtimezone)
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")
 }
})
Example (Withtimezone_and_year)
est, _ := time.LoadLocation("EST")
i := []byte(`<13>Jan 30 02:08:03 host app: Test`)
p := NewParser(WithTimezone(est), WithYear(Year{YYYY: 1987}))
m, _ := p.Parse(i)
output(m)
Output:

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

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewMachine

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

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

func NewParser

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

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

func WithBestEffort

func WithBestEffort() syslog.MachineOption

WithBestEffort enables the best effort mode.

func WithRFC3339

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

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

func WithYear(o YearOperator) syslog.MachineOption

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

Types

type CurrentYear

type CurrentYear struct{}

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

func (CurrentYear) Apply

func (CurrentYear) Apply() int

Apply gets the current year

type SyslogMessage

type SyslogMessage struct {
	syslog.Base
}

SyslogMessage represents a RFC3164 syslog message.

type Year

type Year struct {
	YYYY int
}

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

func (Year) Apply

func (y Year) Apply() int

Apply gets the specified year

type YearOperation

type YearOperation struct {
	Operator YearOperator
}

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

func (YearOperation) Operate

func (y YearOperation) Operate() int

Operate gets the year depending on the current strategy.

type YearOperator

type YearOperator interface {
	Apply() int
}

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL