Documentation
¶
Overview ¶
Package level defines the Level type and built-in level constants for clog.
This package exists so that both the root clog package and subpackages like style can reference Level without circular imports.
Index ¶
Constants ¶
const ( TraceValue = "trace" DebugValue = "debug" InfoValue = "info" HintValue = "hint" DryValue = "dry" WarnValue = "warn" ErrorValue = "error" FatalValue = "fatal" )
Level name strings.
Variables ¶
var ErrUnknownLevel = errors.New("unknown level")
ErrUnknownLevel is returned when a level string or value is not recognized.
Functions ¶
func Register ¶
Register adds a custom level with the given name and short label. It panics if l conflicts with a built-in level.
func Unregister ¶
func Unregister(l Level)
Unregister removes a previously registered custom level. It is a no-op for built-in levels.
Types ¶
type Level ¶
type Level int
Level represents a log level. Lower values are more verbose.
Level implements encoding.TextMarshaler and encoding.TextUnmarshaler, so it works directly with flag.TextVar and most flag libraries.
const ( Trace Level = -10 Debug Level = -5 Info Level = 0 Hint Level = 1 Dry Level = 2 Warn Level = 5 Error Level = 10 Fatal Level = 15 // Unset is passed to [clog.SetNonTTYLevel] to disable the non-TTY level // filter. Its value is intentionally below all real log levels so the // check e.level < nonTTYLevel is always false, meaning no restriction. Unset Level = -1 << 30 )
func Parse ¶
Parse maps a level name string to a Level value. It accepts the canonical names ("trace", "debug", "info", "hint", "dry", "warn", "error", "fatal") plus aliases ("warning" → Warn, "critical" → Fatal). Matching is case-insensitive.
func (Level) MarshalText ¶
MarshalText implements encoding.TextMarshaler.
func (Level) Name ¶
Name returns the canonical name for the level (e.g. "info", "error"), or "" for unknown levels.
func (*Level) UnmarshalText ¶
UnmarshalText implements encoding.TextUnmarshaler.