1
0
mirror of https://github.com/go-kratos/kratos.git synced 2025-01-30 04:31:03 +02:00
kratos/log/level.go

57 lines
970 B
Go
Raw Normal View History

2021-02-17 17:14:47 +08:00
package log
import "strings"
2021-02-17 17:14:47 +08:00
// Level is a logger level.
type Level int8
// LevelKey is logger level key.
const LevelKey = "level"
2021-02-17 17:14:47 +08:00
const (
// LevelDebug is logger debug level.
2021-06-24 18:04:55 +08:00
LevelDebug Level = iota - 1
2021-02-17 17:14:47 +08:00
// LevelInfo is logger info level.
LevelInfo
// LevelWarn is logger warn level.
LevelWarn
// LevelError is logger error level.
LevelError
2021-06-16 14:53:44 +08:00
// LevelFatal is logger fatal level
LevelFatal
2021-02-17 17:14:47 +08:00
)
func (l Level) String() string {
switch l {
case LevelDebug:
return "DEBUG"
case LevelInfo:
return "INFO"
case LevelWarn:
return "WARN"
case LevelError:
return "ERROR"
2021-06-16 14:53:44 +08:00
case LevelFatal:
return "FATAL"
2021-02-17 17:14:47 +08:00
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
2021-06-16 14:53:44 +08:00
case "FATAL":
return LevelFatal
}
return LevelInfo
}