-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogLevel.go
58 lines (51 loc) · 1.42 KB
/
logLevel.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
package jobrunner
// LogLevel is the severity level of logging
type LogLevel int
// These are the enum definitions of log types and presets
const (
LogLevelDebug LogLevel = iota
LogLevelInfo
LogLevelWarn
LogLevelError
LogLevelFatal
maxLogLevel
)
// These are the string representations of log category and preset names
const (
debugLogLevelName string = "Debug"
infoLogLevelName string = "Info"
warnLogLevelName string = "Warn"
errorLogLevelName string = "Error"
fatalLogLevelName string = "Fatal"
)
var supportedLogLevels = map[LogLevel]string{
LogLevelDebug: debugLogLevelName,
LogLevelInfo: infoLogLevelName,
LogLevelWarn: warnLogLevelName,
LogLevelError: errorLogLevelName,
LogLevelFatal: fatalLogLevelName,
}
var logLevelNameMapping = map[string]LogLevel{
debugLogLevelName: LogLevelDebug,
infoLogLevelName: LogLevelInfo,
warnLogLevelName: LogLevelWarn,
errorLogLevelName: LogLevelError,
fatalLogLevelName: LogLevelFatal,
}
// FromString converts a LogLevel flag instance to its string representation
func (logLevel LogLevel) String() string {
for key, value := range supportedLogLevels {
if logLevel == key {
return value
}
}
return debugLogLevelName
}
// NewLogLevel converts a string representation of LogLevel flag to its strongly typed instance
func NewLogLevel(value string) LogLevel {
var logLevel, found = logLevelNameMapping[value]
if !found {
return LogLevelDebug
}
return logLevel
}