level

package
v0.3.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 13, 2026 License: MIT Imports: 3 Imported by: 0

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

View Source
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

View Source
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

func ParseLevel(name string) (lvl Level, err error)

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.

func (Level) String

func (l Level) String() string

String returns the uppercase textual label associated with the Level receiver.

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

func NewVar(initial Level) *Var

NewVar returns a Var initialised to initial. The returned pointer is the Leveler a gate or sink holds; callers later retune it with Set.

func (*Var) Level

func (v *Var) Level() Level

Level reports the current threshold. The load is atomic and lock-free, keeping it cheap enough for a per-record gate to call on the hot path.

func (*Var) Set

func (v *Var) Set(lvl Level)

Set replaces the current threshold with lvl. The store is atomic, so a concurrent Level caller observes either the old or the new value, never a torn read.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL