logger

package
v0.203.0 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2026 License: Apache-2.0 Imports: 2 Imported by: 11 modules, 23 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

Index

Constants

View Source
const (
	LevelTrace = -8
	LevelDebug = -4
	LevelInfo  = 0
	LevelWarn  = 4
	LevelError = 8
)

Variables

This section is empty.

Functions

func Debugf

func Debugf(ctx context.Context, format string, v ...any)

func Errorf

func Errorf(ctx context.Context, format string, v ...any)

func Infof

func Infof(ctx context.Context, format string, v ...any)

func NewContext added in v0.5.0

func NewContext(ctx context.Context, logger Logger) context.Context

NewContext returns a new Context that carries the specified logger.

func Tracef

func Tracef(ctx context.Context, format string, v ...any)

func Warnf

func Warnf(ctx context.Context, format string, v ...any)

Types

type Level added in v0.5.0

type Level int

Level maps to the logging levels in Logger.

type Logger

type Logger interface {
	// Enabled returns if logging at the specified level is enabled.
	// This can be used to avoid computating an expensive value if it
	// won't be logged anyway.
	Enabled(ctx context.Context, level Level) bool

	// Tracef logs a formatted string at [LevelTrace].
	Tracef(ctx context.Context, format string, v ...any)

	// Debugf logs a formatted string at [LevelDebug].
	Debugf(ctx context.Context, format string, v ...any)

	// Infof logs a formatted string at [LevelInfo].
	Infof(ctx context.Context, format string, v ...any)

	// Warnf logs a formatted string at [LevelWarn].
	Warnf(ctx context.Context, format string, v ...any)

	// Errorf logs a formatted string at [LevelError].
	Errorf(ctx context.Context, format string, v ...any)
}
var DefaultLogger Logger = &SimpleLogger{}

func FromContext added in v0.5.0

func FromContext(ctx context.Context) (Logger, bool)

FromContext returns the Logger value stored in ctx, if any.

func Get added in v0.5.0

func Get(ctx context.Context) Logger

Get returns either the logger configured on the context, or the global logger if one isn't defined.

type SimpleLogger

type SimpleLogger struct {
	Level Level
}

func (*SimpleLogger) Debugf

func (l *SimpleLogger) Debugf(ctx context.Context, format string, v ...any)

func (*SimpleLogger) Enabled added in v0.5.0

func (l *SimpleLogger) Enabled(_ context.Context, level Level) bool

func (*SimpleLogger) Errorf

func (l *SimpleLogger) Errorf(ctx context.Context, format string, v ...any)

func (*SimpleLogger) Infof

func (l *SimpleLogger) Infof(ctx context.Context, format string, v ...any)

func (*SimpleLogger) Tracef

func (l *SimpleLogger) Tracef(ctx context.Context, format string, v ...any)

func (*SimpleLogger) Warnf

func (l *SimpleLogger) Warnf(ctx context.Context, format string, v ...any)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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