-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathpriority.go
More file actions
73 lines (63 loc) · 1.35 KB
/
Copy pathpriority.go
File metadata and controls
73 lines (63 loc) · 1.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package syslog
import "errors"
var (
errFacilityOutOfRange = errors.New("syslog: facility out of range (0-23)")
errSeverityOutOfRange = errors.New("syslog: severity out of range (0-7)")
)
// Facility is the syslog facility code (0-23).
type Facility uint8
const (
FacKern Facility = iota
FacUser
FacMail
FacDaemon
FacAuth
FacSyslog
FacLPR
FacNews
FacUUCP
FacCron
FacAuthPriv
FacFTP
FacNTP
FacAudit
FacAlert
FacClock
FacLocal0
FacLocal1
FacLocal2
FacLocal3
FacLocal4
FacLocal5
FacLocal6
FacLocal7
)
// Severity is the syslog severity code (0-7).
type Severity uint8
const (
SevEmerg Severity = iota
SevAlert
SevCrit
SevErr
SevWarning
SevNotice
SevInfo
SevDebug
)
// Priority encodes a facility and severity as PRI = facility*8 + severity.
type Priority uint8
// NewPriority returns a valid Priority from facility and severity. It returns
// an error if either argument is outside its valid range.
func NewPriority(f Facility, s Severity) (Priority, error) {
if f > 23 {
return 0, errFacilityOutOfRange
}
if s > 7 {
return 0, errSeverityOutOfRange
}
return Priority(uint8(f)*8 + uint8(s)), nil
}
// Facility returns the facility part of the priority.
func (p Priority) Facility() Facility { return Facility(p / 8) }
// Severity returns the severity part of the priority.
func (p Priority) Severity() Severity { return Severity(p % 8) }