-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlevel.go
More file actions
58 lines (53 loc) · 1.01 KB
/
level.go
File metadata and controls
58 lines (53 loc) · 1.01 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
package flog
import (
"fmt"
"strconv"
"strings"
)
type Level int8
const (
LEVEL_DISABLED = iota - 1
LEVEL_FATAL
LEVEL_ERROR
LEVEL_WARN
LEVEL_INFO
LEVEL_DEBUG
)
func (l Level) String() string {
switch l {
case LEVEL_DISABLED:
return "DISABLED"
case LEVEL_FATAL:
return "FATAL"
case LEVEL_ERROR:
return "ERROR"
case LEVEL_WARN:
return "WARN"
case LEVEL_INFO:
return "INFO"
case LEVEL_DEBUG:
return "DEBUG"
default:
return strconv.Itoa(int(l))
}
}
// ParseLevel converts a level string into a zerolog Level value.
// returns an error if the input string does not match known values.
func ParseLevel(levelStr string) (Level, error) {
switch strings.ToLower(levelStr) {
case "disabled":
return LEVEL_DISABLED, nil
case "fatal":
return LEVEL_FATAL, nil
case "error":
return LEVEL_ERROR, nil
case "warn":
return LEVEL_WARN, nil
case "info":
return LEVEL_INFO, nil
case "debug":
return LEVEL_DEBUG, nil
default:
return LEVEL_INFO, fmt.Errorf("unknown level '%s'", levelStr)
}
}