You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
crate/log/logsdk/level.go

75 lines
1.4 KiB
Go

2 years ago
package logsdk
import "fmt"
// Level 日志等级
type Level int
func (level Level) String() string {
if b, err := level.MarshalText(); err == nil {
return string(b)
}
return "unknown"
}
func (level Level) MarshalText() ([]byte, error) {
switch level {
case LevelPanic:
return []byte(LevelPanicValue), nil
case LevelFatal:
return []byte(LevelFatalValue), nil
case LevelError:
return []byte(LevelErrorValue), nil
case LevelWarn:
return []byte(LevelWarnValue), nil
case LevelInfo:
return []byte(LevelInfoValue), nil
case LevelDebug:
return []byte(LevelDebugValue), nil
case LevelTrace:
return []byte(LevelTraceValue), nil
}
return nil, fmt.Errorf("not a valid log level %d", level)
}
const (
// LevelCount 日志等级的个数
LevelCount = 7
// LevelOffset 是把 LevelInfo 等级的日志值偏移到零值的偏移量
LevelOffset = 4
)
const (
// LevelDisabled 表示不处理任何等级的日志,
// 其他日志等级的值越小表示日志严重程度越高.
LevelDisabled Level = iota - LevelOffset - 1
LevelPanic
LevelFatal
LevelError
LevelWarn
LevelInfo
LevelDebug
LevelTrace
)
const (
LevelPanicValue = "panic"
LevelFatalValue = "fatal"
LevelErrorValue = "error"
LevelWarnValue = "warn"
LevelInfoValue = "info"
LevelDebugValue = "debug"
LevelTraceValue = "trace"
)
var AllLevels = []Level{
LevelPanic,
LevelFatal,
LevelError,
LevelWarn,
LevelInfo,
LevelDebug,
LevelTrace,
}