forked from mailgun/log
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathseverity.go
40 lines (34 loc) · 780 Bytes
/
severity.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
package log
import (
"fmt"
"strings"
)
type Severity int32
// Supported severities.
const (
SeverityDebug Severity = iota
SeverityInfo
SeverityWarning
SeverityError
)
var severityNames = []string{"DEBUG", "INFO", "WARN", "ERROR"}
func (s Severity) String() string {
if int(s) < 0 || int(s) >= len(severityNames) {
return "UNKNOWN"
}
return severityNames[s]
}
func SeverityFromString(s string) (Severity, error) {
// Treat empty severity string as INFO to preserve backwards compatibility
// with older configs that did not have that parameter.
if s == "" {
return SeverityInfo, nil
}
s = strings.ToUpper(s)
for idx, name := range severityNames {
if name == s {
return Severity(idx), nil
}
}
return -1, fmt.Errorf("unsupported severity: %s", s)
}