logr

package
v0.5.2 Latest Latest
Warning

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

Go to latest
Published: Jan 27, 2026 License: MPL-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package logr provides a logger that implements the logr interface

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RegisterFlags added in v0.5.1

func RegisterFlags(flags *pflag.FlagSet, cfg *Config)

RegisterFlags adds flags to the given flagset, and, after the flagset is parsed by the caller, the flags populate the returned logger config.

Types

type Config

type Config struct {
	Verbosity int
	Format    string
}

type Format

type Format string
const (
	DefaultFormat Format = "default"
	TextFormat    Format = "text"
	JSONFormat    Format = "json"
)

type LevelHandler

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

A LevelHandler wraps a Handler with an Enabled method that returns false for levels below a minimum.

func NewLevelHandler

func NewLevelHandler(level slog.Leveler, h slog.Handler) *LevelHandler

NewLevelHandler returns a LevelHandler with the given level. All methods except Enabled delegate to h.

func (*LevelHandler) Enabled

func (h *LevelHandler) Enabled(_ context.Context, level slog.Level) bool

Enabled implements Handler.Enabled by reporting whether level is at least as large as h's level.

func (*LevelHandler) Handle

func (h *LevelHandler) Handle(ctx context.Context, r slog.Record) error

Handle implements Handler.Handle.

func (*LevelHandler) Handler

func (h *LevelHandler) Handler() slog.Handler

Handler returns the Handler wrapped by h.

func (*LevelHandler) WithAttrs

func (h *LevelHandler) WithAttrs(attrs []slog.Attr) slog.Handler

WithAttrs implements Handler.WithAttrs.

func (*LevelHandler) WithGroup

func (h *LevelHandler) WithGroup(name string) slog.Handler

WithGroup implements Handler.WithGroup.

type Logger

type Logger struct {
	logr.Logger
	Config
}

Logger wraps the upstream logr logger, adding further functionality.

func Discard

func Discard() Logger

func New

func New(cfg Config) (Logger, error)

New constructs a new logger that satisfies the logr interface

func (Logger) Error added in v0.5.1

func (l Logger) Error(err error, msg string, keysAndValues ...any)

func (Logger) Info added in v0.5.1

func (l Logger) Info(msg string, keysAndValues ...any)

func (Logger) V added in v0.5.1

func (l Logger) V(level int) Logger

func (Logger) WithValues added in v0.5.1

func (l Logger) WithValues(keysAndValues ...any) Logger

WithValues returns a new Logger instance with additional key/value pairs. See Info for documentation on how key/value pairs work.

Jump to

Keyboard shortcuts

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