Documentation
¶
Overview ¶
Package level — range 0.2.17.* (ADR 0006 core/logger/level block).
Package level — declares the typed sentinel returned by ParseLevel. The var name equals its errs.Define Reason in SCREAMING_SNAKE form; the code lives in codes.go (range 0.2.17.*).
Package level defines severity levels for log records. It is a core/logger sub-package (logger-domain vocabulary, so not kernel) and remains stdlib-only: no dependency beyond the Go standard library, and specifically never log/slog.
Package level — compile-time interface conformance assertions.
Package level — Leveler port (a live, mutable severity threshold).
Package level — ParseLevel, the inverse of a lowercased Level.String.
Package level — Var, the atomic Level holder behind the Leveler port.
Index ¶
Constants ¶
const CodeLevelUnknown errs.Code = 0x00_02_11_01 // 0.2.17.1
CodeLevelUnknown identifies a ParseLevel call whose input does not match any of the four canonical lowercase level names (debug / info / warn / error).
Variables ¶
var LevelUnknown = errs.Define(CodeLevelUnknown, "LEVEL_UNKNOWN",
"log level name is not recognised",
"internal/core/logger/level.ParseLevel called with an unrecognised name")
LevelUnknown is returned by ParseLevel when the input string does not name one of the four canonical levels (debug / info / warn / error). The offending input is intentionally not echoed into the error so a hostile config value cannot leak through the message; callers parsing untrusted env/config strings get a stable, redaction-safe sentinel matchable via errs.HasCode or errors.Is.
Functions ¶
This section is empty.
Types ¶
type Level ¶
type Level int8
Level represents the importance of a log record; higher values are more severe.
const Debug Level = -4
Debug represents detailed tracing information useful during development.
const Error Level = 8
Error represents failures that usually signal a broken invariant and require action.
const Info Level = 0
Info represents routine operational events occurring during normal execution.
const Warn Level = 4
Warn represents abnormal but recoverable conditions worth human attention.
func ParseLevel ¶
ParseLevel maps a canonical lowercase level name to its Level constant. It is the inverse of Level.String lowercased: "debug", "info", "warn", and "error" round-trip to Debug, Info, Warn, and Error respectively. Input is trimmed of surrounding whitespace and lowercased before matching, so "INFO" and " Warn " resolve too. Any other input yields the zero Level and the LevelUnknown sentinel, so callers parse an env/config string then feed the result to Var.Set.
type Leveler ¶
type Leveler interface {
// Level reports the current threshold; implementations MUST be safe for
// concurrent callers reading while another goroutine mutates the value.
Level() Level
}
Leveler exposes a single live severity threshold. A gate or sink consults Level on each record so the floor can change at runtime, instead of freezing a value at construction. Var is the canonical atomic implementation; any constant threshold can satisfy the interface by returning a fixed Level.
type Var ¶
type Var struct {
// contains filtered or unexported fields
}
Var is an atomically mutable Level holder satisfying Leveler. Its zero value is ready to use and reports Info (the Level zero value), so a freshly declared Var gates at the same default as a config's unset MinLevel. Set and Level are safe for concurrent use; a gate may read Level on the hot path while a control goroutine raises or lowers the floor via Set.
func NewVar ¶
NewVar returns a Var initialised to initial. The returned pointer is the Leveler a gate or sink holds; callers later retune it with Set.