You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
57 lines
970 B
57 lines
970 B
2 years ago
|
package log
|
||
|
|
||
|
import "strings"
|
||
|
|
||
|
// Level is a logger level.
|
||
|
type Level int8
|
||
|
|
||
|
// LevelKey is logger level key.
|
||
|
const LevelKey = "level"
|
||
|
|
||
|
const (
|
||
|
// LevelDebug is logger debug level.
|
||
|
LevelDebug Level = iota - 1
|
||
|
// LevelInfo is logger info level.
|
||
|
LevelInfo
|
||
|
// LevelWarn is logger warn level.
|
||
|
LevelWarn
|
||
|
// LevelError is logger error level.
|
||
|
LevelError
|
||
|
// LevelFatal is logger fatal level
|
||
|
LevelFatal
|
||
|
)
|
||
|
|
||
|
func (l Level) String() string {
|
||
|
switch l {
|
||
|
case LevelDebug:
|
||
|
return "DEBUG"
|
||
|
case LevelInfo:
|
||
|
return "INFO"
|
||
|
case LevelWarn:
|
||
|
return "WARN"
|
||
|
case LevelError:
|
||
|
return "ERROR"
|
||
|
case LevelFatal:
|
||
|
return "FATAL"
|
||
|
default:
|
||
|
return ""
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// ParseLevel parses a level string into a logger Level value.
|
||
|
func ParseLevel(s string) Level {
|
||
|
switch strings.ToUpper(s) {
|
||
|
case "DEBUG":
|
||
|
return LevelDebug
|
||
|
case "INFO":
|
||
|
return LevelInfo
|
||
|
case "WARN":
|
||
|
return LevelWarn
|
||
|
case "ERROR":
|
||
|
return LevelError
|
||
|
case "FATAL":
|
||
|
return LevelFatal
|
||
|
}
|
||
|
return LevelInfo
|
||
|
}
|