forked from papertrail/remote_syslog2
/
priorities.go
109 lines (100 loc) · 1.86 KB
/
priorities.go
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
package syslog
import (
"fmt"
)
// A Syslog Priority is a combination of Severity and Facility.
type Priority int
// Returned when looking up a non-existant facility or severity
var ErrPriority = fmt.Errorf("Not a designated priority")
// RFC5424 Severities
const (
SevEmerg Priority = iota
SevAlert
SevCrit
SevErr
SevWarning
SevNotice
SevInfo
SevDebug
)
var severities = map[string]Priority{
"emerg": SevEmerg,
"alert": SevAlert,
"crit": SevCrit,
"err": SevErr,
"warn": SevWarning,
"notice": SevNotice,
"info": SevInfo,
"debug": SevDebug,
}
// Severity returns the named severity. It returns ErrPriority if the severity
// does not exist.
func Severity(name string) (Priority, error) {
p, ok := severities[name]
if !ok {
return 0, ErrPriority
}
return p, nil
}
// RFC5424 Facilities
const (
LogKern Priority = iota
LogUser
LogMail
LogDaemon
LogAuth
LogSyslog
LogLPR
LogNews
LogUUCP
LogCron
LogAuthPriv
LogFTP
LogNTP
LogAudit
LogAlert
LogAt
LogLocal0
LogLocal1
LogLocal2
LogLocal3
LogLocal4
LogLocal5
LogLocal6
LogLocal7
)
var facilities = map[string]Priority{
"kern": LogKern,
"user": LogUser,
"mail": LogMail,
"daemon": LogDaemon,
"auth": LogAuth,
"syslog": LogSyslog,
"lpr": LogLPR,
"news": LogNews,
"uucp": LogUUCP,
"cron": LogCron,
"authpriv": LogAuthPriv,
"ftp": LogFTP,
"ntp": LogNTP,
"audit": LogAudit,
"alert": LogAlert,
"at": LogAt,
"local0": LogLocal0,
"local1": LogLocal1,
"local2": LogLocal2,
"local3": LogLocal3,
"local4": LogLocal4,
"local5": LogLocal5,
"local6": LogLocal6,
"local7": LogLocal7,
}
// Facility returns the named facility. It returns ErrPriority if the facility
// does not exist.
func Facility(name string) (Priority, error) {
p, ok := facilities[name]
if !ok {
return 0, ErrPriority
}
return p, nil
}