mirror of
https://github.com/SagerNet/sing-box.git
synced 2024-11-09 18:43:14 +00:00
60 lines
952 B
Go
60 lines
952 B
Go
|
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)
|
||
|
}
|
||
|
}
|