logger

package
v1.16.0 Latest Latest
Warning

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

Go to latest
Published: Jan 9, 2025 License: GPL-2.0, GPL-3.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Debug added in v1.16.0

func Debug(ctx context.Context, msg string, tags ...any)

Debug logs a message with debug level.

func Debugf added in v1.16.0

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

Debugf logs a formatted message with debug level.

func Error added in v1.16.0

func Error(ctx context.Context, msg string, tags ...any)

Error logs a message with error level.

func Errorf added in v1.16.0

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

Errorf logs a formatted message with error level.

func Fatal added in v1.16.0

func Fatal(ctx context.Context, msg string, tags ...any)

Fatal logs a message with fatal level and exits the program.

func Fatalf added in v1.16.0

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

Fatalf logs a formatted message with fatal level and exits the program.

func Info added in v1.16.0

func Info(ctx context.Context, msg string, tags ...any)

Info logs a message with info level.

func Infof added in v1.16.0

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

Infof logs a formatted message with info level.

func Warn added in v1.16.0

func Warn(ctx context.Context, msg string, tags ...any)

Warn logs a message with warn level.

func Warnf added in v1.16.0

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

Warnf logs a formatted message with warn level.

func WithFixedLogger added in v1.16.0

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

WithFixedLogger returns a new context with the given fixed logger. This is only used for testing.

func WithLogger added in v1.16.0

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

WithLogger returns a new context with the given logger.

func Write added in v1.16.0

func Write(ctx context.Context, msg string)

Write writes a message with free form.

Types

type Config added in v1.16.0

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

type Logger

type Logger interface {
	Debug(msg string, tags ...any)
	Info(msg string, tags ...any)
	Warn(msg string, tags ...any)
	Error(msg string, tags ...any)
	Fatal(msg string, tags ...any)

	Debugf(format string, v ...any)
	Infof(format string, v ...any)
	Warnf(format string, v ...any)
	Errorf(format string, v ...any)
	Fatalf(format string, v ...any)

	With(attrs ...any) Logger
	WithGroup(name string) Logger

	// Write writes a message to the logger in free form.
	Write(string)
}

func FromContext added in v1.16.0

func FromContext(ctx context.Context) Logger

FromContext returns a logger from the given context.

func NewLogger

func NewLogger(opts ...Option) Logger

type Option added in v1.16.0

type Option func(*Config)

func WithDebug added in v1.16.0

func WithDebug() Option

WithDebug sets the level of the logger to debug.

func WithFormat added in v1.16.0

func WithFormat(format string) Option

WithFormat sets the format of the logger (text or json).

func WithQuiet added in v1.16.0

func WithQuiet() Option

WithQuiet suppresses output to stderr.

func WithWriter added in v1.16.0

func WithWriter(w io.Writer) Option

WithWriter sets the file to write logs to.

Jump to

Keyboard shortcuts

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