sing-box/log/level.go

60 lines
952 B
Go
Raw Permalink Normal View History

2022-07-12 07:17:29 +00:00
package log
import (
E "github.com/sagernet/sing/common/exceptions"
)
type Level = uint8
const (
LevelPanic Level = iota
LevelFatal
LevelError
LevelWarn
LevelInfo
LevelDebug
LevelTrace
)
func FormatLevel(level Level) string {
switch level {
case LevelTrace:
return "trace"
case LevelDebug:
return "debug"
case LevelInfo:
return "info"
case LevelWarn:
return "warn"
case LevelError:
return "error"
case LevelFatal:
return "fatal"
case LevelPanic:
return "panic"
default:
return "unknown"
}
}
func ParseLevel(level string) (Level, error) {
switch level {
case "trace":
return LevelTrace, nil
case "debug":
return LevelDebug, nil
case "info":
return LevelInfo, nil
case "warn", "warning":
return LevelWarn, nil
case "error":
return LevelError, nil
case "fatal":
return LevelFatal, nil
case "panic":
return LevelPanic, nil
default:
return LevelTrace, E.New("unknown log level: ", level)
}
}