代码拉取完成,页面将自动刷新
package logger
import (
"fmt"
"strings"
)
const (
// PanicLevel indicates a very serious event at the highest level.
PanicLevel Level = iota + 1
// FatalLevel indicates that an event occurred that the application
// cannot continue to run.
FatalLevel
// ErrorLevel indicates that an event occurred within the application
// but does not affect continued operation.
ErrorLevel
// WarnLevel indicates that a noteworthy event has occurred inside
// the application.
WarnLevel
// InfoLevel represents some general information events.
InfoLevel
// DebugLevel represents some informational events for debugging, and
// very verbose logging.
DebugLevel
// TraceLevel represents the finest granular information event.
TraceLevel
)
// Level is the level of the log.
type Level uint32
// All supported log levels.
var allLevels = map[Level][]string{
PanicLevel: {"panic", "PANIC", "pnc", "PNC"},
FatalLevel: {"fatal", "FATAL", "fat", "FAT"},
ErrorLevel: {"error", "ERROR", "err", "ERR"},
WarnLevel: {"warn", "WARN", "wan", "WAN"},
InfoLevel: {"info", "INFO", "inf", "INF"},
DebugLevel: {"debug", "DEBUG", "dbg", "DBG"},
TraceLevel: {"trace", "TRACE", "tac", "TAC"},
}
// String returns the string form of the current level.
// If the log level is not supported, always returns "unknown".
func (level Level) String() string {
if s, found := allLevels[level]; found {
return s[0]
}
return "unknown"
}
// CapitalString returns the capital string form of the current level.
// If the log level is not supported, always returns "UNKNOWN".
func (level Level) CapitalString() string {
if s, found := allLevels[level]; found {
return s[1]
}
return "UNKNOWN"
}
// ShortString returns the short string form of the current level.
// If the log level is not supported, always returns "uno".
func (level Level) ShortString() string {
if s, found := allLevels[level]; found {
return s[2]
}
return "uno"
}
// ShortCapitalString returns the short capital string form of the current level.
// If the log level is not supported, always returns "UNO".
func (level Level) ShortCapitalString() string {
if s, found := allLevels[level]; found {
return s[3]
}
return "UNO"
}
// IsValid determines whether the current level is valid.
func (level Level) IsValid() bool {
return level <= TraceLevel && level >= PanicLevel
}
// IsEnabled returns whether the given level is included in the current level.
func (level Level) IsEnabled(l Level) bool {
return l <= level && l > 0
}
// ParseLevel parses the log level from the given string.
func ParseLevel(s string) (Level, error) {
switch strings.ToLower(strings.TrimSpace(s)) {
case "panic", "pnc":
return PanicLevel, nil
case "fatal", "fat":
return FatalLevel, nil
case "error", "err":
return ErrorLevel, nil
case "warn", "wan", "warning":
return WarnLevel, nil
case "info", "inf", "echo":
return InfoLevel, nil
case "debug", "dbg":
return DebugLevel, nil
case "trace", "tac", "print":
return TraceLevel, nil
}
// A level zero value is not a supported level.
return 0, fmt.Errorf("invalid log level string %q", s)
}
// MustParseLevel parses the log level from the given string.
// If the given string is invalid, it will panic.
func MustParseLevel(s string) Level {
level, err := ParseLevel(s)
if err != nil {
panic(err)
}
return level
}
// GetAllLevels returns all supported log levels.
func GetAllLevels() []Level {
return []Level{PanicLevel, FatalLevel, ErrorLevel, WarnLevel, InfoLevel, DebugLevel, TraceLevel}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。