-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
priority.go
157 lines (144 loc) · 4.05 KB
/
priority.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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
// SPDX-FileCopyrightText: 2021-2023 Winni Neessen <[email protected]>
//
// SPDX-License-Identifier: MIT
package parsesyslog
// SeverityMask is the bitmask representing the Severity in the Priority
const SeverityMask = 0x07
// Severity represents the serverity part of the Syslog PRI header
type Severity int
// Facility represents the facility part of the Syslog PRI header
type Facility int
// Priority represents the Syslog PRI header
type Priority int
// Severities
const (
Emergency Priority = iota // System is unusable
Alert // Action must be taken immediately
Crit // Critical conditions
Error // Error conditions
Warning // Warning conditions
Notice // Normal but significant conditions
Info // Informational messages
Debug // Debug-level messages
)
// Facilities
const (
Kern Priority = iota << 3 // Kernel messages
User // User-level messages
Mail // Mail system
Daemon // System daemons
Auth // Security/authentication messages
Syslog // Messages generated internally by the syslog daemon
LPR // Printer subsystem
News // Network News subsystem
UUCP // UUCP subsystem
Cron // Cron subsystem
AuthPriv // Security/authentication messages
FTP // FTP daemon
NTP // NTP subsystem
Security // Log audit
Console // Log alert
SolarisCron // Scheduling daemon
Local0 // Locally used facilities
Local1 // Locally used facilities
Local2 // Locally used facilities
Local3 // Locally used facilities
Local4 // Locally used facilities
Local5 // Locally used facilities
Local6 // Locally used facilities
Local7 // Locally used facilities
)
// FacilityFromPrio extracts the Facility from a given Priority
func FacilityFromPrio(p Priority) Facility {
return Facility(p >> 3)
}
// SeverityFromPrio extracts the Facility from a given Priority
func SeverityFromPrio(p Priority) Severity {
return Severity(p & SeverityMask)
}
// FacilityStringFromPrio returns a string representation of the Facility of a given Priority
func FacilityStringFromPrio(p Priority) string {
return FacilityFromPrio(p).String()
}
// SeverityStringFromPrio returns a string representation of the Severity of a given Priority
func SeverityStringFromPrio(p Priority) string {
return SeverityFromPrio(p).String()
}
// String satisfies the fmt.Stringer interface for the Facility type
func (f Facility) String() string {
switch f {
case 0:
return "KERN"
case 1:
return "USER"
case 2:
return "MAIL"
case 3:
return "DAEMON"
case 4:
return "AUTH"
case 5:
return "SYSLOG"
case 6:
return "LPR"
case 7:
return "NEWS"
case 8:
return "UUCP"
case 9:
return "CRON"
case 10:
return "AUTHPRIV"
case 11:
return "FTP"
case 12:
return "NTP"
case 13:
return "SECURITY"
case 14:
return "CONSOLE"
case 15:
return "SOLARISCRON"
case 16:
return "LOCAL0"
case 17:
return "LOCAL1"
case 18:
return "LOCAL2"
case 19:
return "LOCAL3"
case 20:
return "LOCAL4"
case 21:
return "LOCAL5"
case 22:
return "LOCAL6"
case 23:
return "LOCAL7"
default:
return "UNKNOWN"
}
}
// String satisfies the fmt.Stringer interface for the Severity type
func (s Severity) String() string {
switch s {
case 0:
return "EMERGENCY"
case 1:
return "ALERT"
case 2:
return "CRIT"
case 3:
return "ERROR"
case 4:
return "WARNING"
case 5:
return "NOTICE"
case 6:
return "INFO"
case 7:
return "DEBUG"
default:
return "UNKNOWN"
}
}