logger

package
v1.30.3 Latest Latest
Warning

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

Go to latest
Published: Jan 4, 2026 License: GPL-3.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Debug

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

Debug logs a message with debug level.

func Debugf

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

Debugf logs a formatted message with debug level.

func Error

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

Error logs a message with error level.

func Errorf

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

Errorf logs a formatted message with error level.

func Fatal

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

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

func Fatalf

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

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

func Info

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

Info logs a message with info level.

func Infof

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

Infof logs a formatted message with info level.

func Warn

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

Warn logs a message with warn level.

func Warnf

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

Warnf logs a formatted message with warn level.

func WithFixedLogger

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

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

WithLogger returns a new context with the given logger.

func WithValues

func WithValues(ctx context.Context, attrs ...slog.Attr) context.Context

WithValues adds attributes to the context for structured logging

func Write

func Write(ctx context.Context, msg string)

Write writes a message with free form.

Types

type Config

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

type Logger

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

	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 ...slog.Attr) Logger
	WithGroup(name string) Logger

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

func FromContext

func FromContext(ctx context.Context) Logger

FromContext returns a logger from the given context.

func NewLogger

func NewLogger(opts ...Option) Logger

type Option

type Option func(*Config)

func WithDebug

func WithDebug() Option

WithDebug sets the level of the logger to debug.

func WithFormat

func WithFormat(format string) Option

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

func WithQuiet

func WithQuiet() Option

WithQuiet suppresses output to stderr.

func WithWriter

func WithWriter(w io.Writer) Option

WithWriter sets the file to write logs to.

Directories

Path Synopsis
Package tag provides standardized tag functions for structured logging.
Package tag provides standardized tag functions for structured logging.

Jump to

Keyboard shortcuts

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