level

package
v0.11.15 Latest Latest
Warning

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

Go to latest
Published: Jul 4, 2026 License: MIT Imports: 5 Imported by: 0

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

View Source
const (
	TraceValue = "trace"
	DebugValue = "debug"
	InfoValue  = "info"
	HintValue  = "hint"
	DryValue   = "dry"
	WarnValue  = "warn"
	ErrorValue = "error"
	FatalValue = "fatal"
)

Level name strings.

Variables

View Source
var ErrUnknownLevel = errors.New("unknown level")

ErrUnknownLevel is returned when a level string or value is not recognized.

Functions

func All

func All() map[string]Level

All returns all registered level names (built-in + custom) mapped to their Level values.

func Labels

func Labels() map[Level]string

Labels returns a copy of all level labels (short display strings like "INF", "ERR").

func Register

func Register(l Level, name, label string)

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

func Parse(s string) (Level, error)

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

func (l Level) MarshalText() ([]byte, error)

MarshalText implements encoding.TextMarshaler.

func (Level) Name

func (l Level) Name() string

Name returns the canonical name for the level (e.g. "info", "error"), or "" for unknown levels.

func (Level) String

func (l Level) String() string

String returns the short label for the level (e.g. "INF", "ERR").

func (*Level) UnmarshalText

func (l *Level) UnmarshalText(text []byte) error

UnmarshalText implements encoding.TextUnmarshaler.

Jump to

Keyboard shortcuts

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