Skip to content

Commit

Permalink
Add facility and severity definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
ysmilda committed Dec 13, 2024
1 parent 7a653c9 commit 98558b8
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 8 deletions.
52 changes: 48 additions & 4 deletions rfc3164/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,56 @@ func NewPRI(value byte) (PRI, error) {
return PRI{value: value}, nil
}

type Facility byte

// Definition taken from https://datatracker.ietf.org/doc/html/rfc3164#section-4.1.1
const (
FacilityKernel Facility = iota
FacilityUser
FacilityMail
FacilitySystem
FacilityAuth
FacilitySyslog
FacilityLPR
FacilityNews
FacilityUUCP
FacilityClock
FacilityAuth2
FacilityFTP
FacilityNTP
FacilityLogAudit
FacilityLogAlert
FacilityClock2
FacilityLocal0
FacilityLocal1
FacilityLocal2
FacilityLocal3
FacilityLocal4
FacilityLocal5
FacilityLocal6
FacilityLocal7
)

// Facility returns the facility value of the PRI.
func (p PRI) Facility() byte {
return p.value & 0xF8 >> 3
func (p PRI) Facility() Facility {
return Facility(p.value & 0xF8 >> 3)
}

type Severity byte

// Definition taken from https://datatracker.ietf.org/doc/html/rfc3164#section-4.1.1
const (
SeverityEmergency Severity = iota
SeverityAlert
SeverityCritical
SeverityError
SeverityWarning
SeverityNotice
SeverityInformational
SeverityDebug
)

// Severity returns the severity value of the PRI.
func (p PRI) Severity() byte {
return p.value & 0x07
func (p PRI) Severity() Severity {
return Severity(p.value & 0x07)
}
52 changes: 48 additions & 4 deletions rfc5424/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,58 @@ func NewPRI(value byte) (PRI, error) {
return PRI{value: value}, nil
}

type Facility byte

// Definition taken from https://datatracker.ietf.org/doc/html/rfc5424#section-6.2.1
const (
FacilityKernel Facility = iota
FacilityUser
FacilityMail
FacilitySystem
FacilityAuth
FacilitySyslog
FacilityLPR
FacilityNews
FacilityUUCP
FacilityClock
FacilityAuth2
FacilityFTP
FacilityNTP
FacilityLogAudit
FacilityLogAlert
FacilityClock2
FacilityLocal0
FacilityLocal1
FacilityLocal2
FacilityLocal3
FacilityLocal4
FacilityLocal5
FacilityLocal6
FacilityLocal7
)

// Facility returns the facility value of the PRI.
func (p PRI) Facility() byte {
return p.value & 0xF8 >> 3
func (p PRI) Facility() Facility {
return Facility(p.value & 0xF8 >> 3)
}

type Severity byte

// Definition taken from https://datatracker.ietf.org/doc/html/rfc5424#section-6.2.1
const (
SeverityEmergency Severity = iota
SeverityAlert
SeverityCritical
SeverityError
SeverityWarning
SeverityNotice
SeverityInformational
SeverityDebug
)

// Severity returns the severity value of the PRI.
func (p PRI) Severity() byte {
return p.value & 0x07
func (p PRI) Severity() Severity {
return Severity(p.value & 0x07)
}

// StructuredDataElement represents a structured data element in a syslog message.
Expand Down

0 comments on commit 98558b8

Please sign in to comment.