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)((len=1) "-") } })
Example (Currentyear) ¶
i := []byte(`<13>Dec 2 16:31:03 host app: Test`) p := NewParser(WithYear(CurrentYear{})) m, _ := p.Parse(i) // Force year to match the one in the comment below x, _ := m.(*SyslogMessage) x.Timestamp = func(t1 *time.Time) *time.Time { currentY := time.Now().Year() t2 := t1.AddDate(2021-currentY, 0, 0) return &t2 }(x.Timestamp) output(m)
Output: (*rfc3164.SyslogMessage)({ Base: (syslog.Base) { Facility: (*uint8)(1), Severity: (*uint8)(5), Priority: (*uint8)(13), Timestamp: (*time.Time)(2021-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 (Stampmicro) ¶
i := []byte(`<28>Dec 2 16:49:23.654321 host app[23410]: Test`) p := NewParser(WithYear(Year{YYYY: 2025}), WithSecondFractions()) m, _ := p.Parse(i) output(m)
Output: (*rfc3164.SyslogMessage)({ Base: (syslog.Base) { Facility: (*uint8)(3), Severity: (*uint8)(4), Priority: (*uint8)(28), Timestamp: (*time.Time)(2025-12-02 16:49:23.654321 +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 (Stampmilli) ¶
i := []byte(`<28>Dec 2 16:49:23.123 host app[23410]: Test`) p := NewParser(WithYear(Year{YYYY: 2025}), WithSecondFractions()) m, _ := p.Parse(i) output(m)
Output: (*rfc3164.SyslogMessage)({ Base: (syslog.Base) { Facility: (*uint8)(3), Severity: (*uint8)(4), Priority: (*uint8)(28), Timestamp: (*time.Time)(2025-12-02 16:49:23.123 +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 (Withlocaletimezone) ¶
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!") } })
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 ¶
- func NewMachine(options ...syslog.MachineOption) syslog.Machine
- func NewParser(options ...syslog.MachineOption) syslog.Machine
- func WithBestEffort() syslog.MachineOption
- func WithLocaleTimezone(loc *time.Location) syslog.MachineOption
- func WithRFC3339() syslog.MachineOption
- func WithSecondFractions() syslog.MachineOption
- func WithTimezone(loc *time.Location) syslog.MachineOption
- func WithYear(o YearOperator) syslog.MachineOption
- type CurrentYear
- type SyslogMessage
- type Year
- type YearOperation
- type YearOperator
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 WithLocaleTimezone ¶
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 ¶
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 WithSecondFractions ¶
func WithSecondFractions() syslog.MachineOption
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.
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.
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.