-
Notifications
You must be signed in to change notification settings - Fork 0
/
level.go
71 lines (63 loc) · 1.68 KB
/
level.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
package logger
import (
"strings"
"github.com/sirupsen/logrus"
)
// Level is an integer representation of the logging level
type Level uint8
const (
// LevelFatal is to be used to log predictable errors that make the service unusable, eg misconfiguration. After logging, the app will be shut down.
LevelFatal = iota
// LevelError isto be used for recoverable errors that limit the service's functionality, eg timeouts.
LevelError
// LevelWarn is to be used for non-critical errors that may require some attention.
LevelWarn
// LevelInfo is to be used for monitoring successful interactions, eg run time or job result.
LevelInfo
// LevelDebug should only be used in dev/test environments.
LevelDebug
)
var nameMapping = map[string]Level{
"fatal": LevelFatal,
"error": LevelError,
"warn": LevelWarn,
"info": LevelInfo,
"debug": LevelDebug,
}
// LevelNameToLevel converts a named log level to the Level type
func LevelNameToLevel(name string) (l Level, ok bool) {
l, ok = nameMapping[strings.ToLower(name)]
return
}
func mapLevelToLogrusLevel(l Level) logrus.Level {
switch l {
case LevelFatal:
return logrus.FatalLevel
case LevelError:
return logrus.ErrorLevel
case LevelWarn:
return logrus.WarnLevel
case LevelInfo:
return logrus.InfoLevel
case LevelDebug:
return logrus.DebugLevel
}
// should never get here
return logrus.DebugLevel
}
func mapLogrusLevelToLevel(l logrus.Level) Level {
switch l {
case logrus.FatalLevel:
return LevelFatal
case logrus.ErrorLevel:
return LevelError
case logrus.WarnLevel:
return LevelWarn
case logrus.InfoLevel:
return LevelInfo
case logrus.DebugLevel:
return LevelDebug
}
// should never get here
return LevelDebug
}