logger

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Apr 5, 2023 License: Apache-2.0 Imports: 2 Imported by: 22

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{}

func (*SimpleLogger) Debugf

func (l *SimpleLogger) Debugf(_ 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(_ context.Context, format string, v ...any)

func (*SimpleLogger) Infof

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

func (*SimpleLogger) Tracef

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

func (*SimpleLogger) Warnf

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

Jump to

Keyboard shortcuts

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