log/新增ParseLevel;

develop log/v0.11.0
Ge Song 2 years ago
parent 850b678c13
commit d83a012967

@ -1,6 +1,8 @@
package logsdk
import "fmt"
import (
"fmt"
)
// Level 日志等级
type Level int
@ -12,6 +14,30 @@ func (level Level) String() string {
return "unknown"
}
// ParseLevel 把 level 字符串解析成 Level,
// 支持的字符串: panic, fatal, error, warn, info, debug, trace,
// 传入不支持的字符串返回 LevelInfo.
func ParseLevel(s string) Level {
switch s {
case LevelPanicValue:
return LevelPanic
case LevelFatalValue:
return LevelFatal
case LevelErrorValue:
return LevelError
case LevelWarnValue:
return LevelWarn
case LevelInfoValue:
return LevelInfo
case LevelDebugValue:
return LevelDebug
case LevelTraceValue:
return LevelTrace
default:
return LevelInfo
}
}
func (level Level) MarshalText() ([]byte, error) {
switch level {
case LevelPanic:

Loading…
Cancel
Save