logr

package
v0.2.4 Latest Latest
Warning

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

Go to latest
Published: Dec 16, 2023 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 Discard

func Discard() logr.Logger

func New

func New(cfg *Config) (logr.Logger, error)

New constructs a new logger that satisfies the logr interface

Types

type Config

type Config struct {
	Verbosity int
	Format    string
}

func NewConfigFromFlags

func NewConfigFromFlags(flags *pflag.FlagSet) *Config

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

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 = logr.Logger

Alias for callers to use so that don't need to import both upstream logr and this logr.

func NewNoopLogger added in v0.2.0

func NewNoopLogger() Logger

type NoopSink added in v0.2.0

type NoopSink struct{}

NoopSink is a log sink that does not log anything.

func (*NoopSink) Enabled added in v0.2.0

func (n *NoopSink) Enabled(level int) bool

func (*NoopSink) Error added in v0.2.0

func (n *NoopSink) Error(error, string, ...any)

func (*NoopSink) Info added in v0.2.0

func (n *NoopSink) Info(int, string, ...any)

func (*NoopSink) Init added in v0.2.0

func (n *NoopSink) Init(info logr.RuntimeInfo)

func (*NoopSink) WithName added in v0.2.0

func (n *NoopSink) WithName(name string) logr.LogSink

func (*NoopSink) WithValues added in v0.2.0

func (n *NoopSink) WithValues(...any) logr.LogSink

Jump to

Keyboard shortcuts

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