types

package
v0.86.0 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2026 License: Apache-2.0 Imports: 9 Imported by: 2 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package types contains the types for the log package.

Index

Constants

View Source
const (
	TraceStr    = "trace"
	DebugStr    = "debug"
	InfoStr     = "info"
	WarnStr     = "warn"
	ErrorStr    = "error"
	CriticalStr = "critical"
	OffStr      = "off"
)

Log level string representations

Variables

This section is empty.

Functions

func ToSlogLevel

func ToSlogLevel(level LogLevel) slog.Level

ToSlogLevel converts a LogLevel to a slog.Level

func ValidateLevelRules added in v0.86.0

func ValidateLevelRules(spec string) error

ValidateLevelRules reports whether spec is a valid log level specification, as accepted by ParseLevelRules.

Types

type LevelRules added in v0.86.0

type LevelRules struct {
	// contains filtered or unexported fields
}

LevelRules is an immutable log level configuration: a default level, applied to any package not selected by a more specific rule, plus any number of per-package overrides.

func NewLevelRules added in v0.86.0

func NewLevelRules(level LogLevel) *LevelRules

NewLevelRules returns a LevelRules applying level by default and no per-package overrides.

func ParseLevelRules added in v0.86.0

func ParseLevelRules(spec, modulePrefix string) (*LevelRules, error)

ParseLevelRules parses a log level specification into a LevelRules.

A specification is a comma-separated list of instructions. Each instruction is either a bare level (e.g. "debug"), which sets the default level applied to any package not selected by a more specific instruction, or "<pattern>=<level>", which overrides the level for the packages selected by pattern:

  • "some/pkg/path" selects exactly that package.
  • "some/pkg/path/..." selects that package and any of its subpackages.
  • "./relative/path" and "./relative/path/..." are the same as above, but relative to modulePrefix.
  • "." alone refers to modulePrefix itself.

When several instructions select the same package, the most specific one wins. At most one bare level may be given; if none is given, the default level is InfoLvl.

func (*LevelRules) DefaultLevel added in v0.86.0

func (c *LevelRules) DefaultLevel() LogLevel

DefaultLevel returns the level applied to packages that don't match any rule in the configuration.

func (*LevelRules) LevelForPC added in v0.86.0

func (c *LevelRules) LevelForPC(pc uintptr) LogLevel

LevelForPC returns the effective log level for the call site identified by pc, as captured by runtime.Callers.

func (*LevelRules) MinLevel added in v0.86.0

func (c *LevelRules) MinLevel() LogLevel

MinLevel returns the most permissive level enabled anywhere by this configuration.

func (*LevelRules) Spec added in v0.86.0

func (c *LevelRules) Spec() string

Spec returns the specification string this configuration corresponds to.

type LogLevel

type LogLevel slog.Level

LogLevel is the type of log levels

Log levels

func FromSlogLevel

func FromSlogLevel(level slog.Level) LogLevel

FromSlogLevel converts a slog.Level to a LogLevel

func ValidateLogLevel added in v0.86.0

func ValidateLogLevel(logLevel string) (LogLevel, error)

ValidateLogLevel validates the given log level and returns the corresponding LogLevel.

func (LogLevel) String

func (level LogLevel) String() string

type LoggerInterface

type LoggerInterface interface {
	// Trace formats message using the default formats for its operands
	// and writes to log with level = Trace
	Trace(v ...interface{})

	// Debug formats message using the default formats for its operands
	// and writes to log with level = Debug
	Debug(v ...interface{})

	// Info formats message using the default formats for its operands
	// and writes to log with level = Info
	Info(v ...interface{})

	// Warn formats message using the default formats for its operands
	// and writes to log with level = Warn
	Warn(v ...interface{}) error

	// Error formats message using the default formats for its operands
	// and writes to log with level = Error
	Error(v ...interface{}) error

	// Critical formats message using the default formats for its operands
	// and writes to log with level = Critical
	Critical(v ...interface{}) error

	// Close flushes all the messages in the logger and closes it. It cannot be used after this operation.
	Close()

	// Flush flushes all the messages in the logger.
	Flush()

	// SetAdditionalStackDepth sets the additional number of frames to skip by runtime.Caller
	SetAdditionalStackDepth(depth int) error

	// Sets logger context that can be used in formatter funcs and custom receivers
	SetContext(context interface{})

	// Tracef formats message according to format specifier
	// and writes to log with level = Trace.
	Tracef(format string, params ...interface{})

	// Debugf formats message according to format specifier
	// and writes to log with level = Debug.
	Debugf(format string, params ...interface{})

	// Infof formats message according to format specifier
	// and writes to log with level = Info.
	Infof(format string, params ...interface{})

	// Warnf formats message according to format specifier
	// and writes to log with level = Warn.
	Warnf(format string, params ...interface{}) error

	// Errorf formats message according to format specifier
	// and writes to log with level = Error.
	Errorf(format string, params ...interface{}) error

	// Criticalf formats message according to format specifier
	// and writes to log with level = Critical.
	Criticalf(format string, params ...interface{}) error
}

LoggerInterface provides basic logging methods that can be used from outside the log package.

type RulesSync added in v0.86.0

type RulesSync struct {
	// contains filtered or unexported fields
}

RulesSync is a dynamically updatable LevelRules holder, safe for concurrent use. It implements slog.Leveler.

func NewRulesSync added in v0.86.0

func NewRulesSync(levelRules *LevelRules) *RulesSync

NewRulesSync returns a RulesSync initialized with levelRules.

func NewRulesSyncFromLevel added in v0.86.0

func NewRulesSyncFromLevel(level LogLevel) *RulesSync

NewRulesSyncFromLevel returns a RulesSync initialized with a single level applying to all packages.

func (*RulesSync) EnabledForPC added in v0.86.0

func (s *RulesSync) EnabledForPC(pc uintptr, level slog.Level) bool

EnabledForPC reports whether level is enabled for the call site identified by pc, as captured by runtime.Callers.

func (*RulesSync) Level added in v0.86.0

func (s *RulesSync) Level() slog.Level

Level implements slog.Leveler.

func (*RulesSync) Load added in v0.86.0

func (s *RulesSync) Load() *LevelRules

Load returns the current LevelRules.

func (*RulesSync) Store added in v0.86.0

func (s *RulesSync) Store(levelRules *LevelRules)

Store atomically replaces the current LevelRules.

Jump to

Keyboard shortcuts

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