logger

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 29, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package logger defines a common logging interface and provides implementations for various logging libraries.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ToContext

func ToContext(ctx context.Context, l Logger) context.Context

ToContext returns a new context with the Logger attached.

Types

type Logger

type Logger interface {
	// With returns a new logger with the given fields.
	With(args ...any) Logger
	// Error logs a message at the error level.
	Error(args ...any)
	// Errorf logs a message at the error level.
	Errorf(format string, args ...any)
	// Fatalf logs a message at the fatal level and calls os.Exit(1).
	Fatalf(format string, args ...any)
	// Fatal logs a message at the fatal level and calls os.Exit(1).
	Fatal(args ...any)
	// Info logs a message at the info level.
	Info(args ...any)
	// Infof logs a message at the info level.
	Infof(format string, args ...any)
	// Warn logs a message at the warn level.
	Warn(args ...any)
	// Warnf logs a message at the warn level.
	Warnf(format string, args ...any)
	// Debug logs a message at the debug level.
	Debug(args ...any)
	// Debugf logs a message at the debug level.
	Debugf(format string, args ...any)
}

Logger is an interface for logging.

func FromContext

func FromContext(ctx context.Context) Logger

FromContext returns the Logger associated with the context. If no Logger is found, it returns a Nop logger.

type Nop

type Nop struct{}

Nop is a logger that does nothing.

func NewNop

func NewNop() Nop

NewNop creates a new Nop.

func (Nop) Debug

func (Nop) Debug(_ ...any)

Debug logs a message at the debug level.

func (Nop) Debugf

func (Nop) Debugf(_ string, _ ...any)

Debugf logs a message at the debug level.

func (Nop) Error

func (Nop) Error(_ ...any)

Error logs a message at the error level.

func (Nop) Errorf

func (Nop) Errorf(_ string, _ ...any)

Errorf logs a message at the error level.

func (Nop) Fatal

func (Nop) Fatal(_ ...any)

Fatal logs a message at the fatal level and calls os.Exit(1).

func (Nop) Fatalf

func (Nop) Fatalf(_ string, _ ...any)

Fatalf logs a message at the fatal level and calls os.Exit(1).

func (Nop) Info

func (Nop) Info(_ ...any)

Info logs a message at the info level.

func (Nop) Infof

func (Nop) Infof(_ string, _ ...any)

Infof logs a message at the info level.

func (Nop) Warn

func (Nop) Warn(_ ...any)

Warn logs a message at the warn level.

func (Nop) Warnf

func (Nop) Warnf(_ string, _ ...any)

Warnf logs a message at the warn level.

func (Nop) With

func (Nop) With(_ ...any) Logger

With returns a new logger with the given fields.

type Slog

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

Slog is a logger that uses the standard library's log/slog package.

func NewSlog

func NewSlog() *Slog

NewSlog creates a new Slog.

func (*Slog) Debug

func (s *Slog) Debug(args ...any)

Debug logs a message at the debug level.

func (*Slog) Debugf

func (s *Slog) Debugf(format string, args ...any)

Debugf logs a message at the debug level.

func (*Slog) Error

func (s *Slog) Error(args ...any)

Error logs a message at the error level.

func (*Slog) Errorf

func (s *Slog) Errorf(format string, args ...any)

Errorf logs a message at the error level.

func (*Slog) Fatal

func (s *Slog) Fatal(args ...any)

Fatal logs a message at the fatal level and calls os.Exit(1).

func (*Slog) Fatalf

func (s *Slog) Fatalf(format string, args ...any)

Fatalf logs a message at the fatal level and calls os.Exit(1).

func (*Slog) Info

func (s *Slog) Info(args ...any)

Info logs a message at the info level.

func (*Slog) Infof

func (s *Slog) Infof(format string, args ...any)

Infof logs a message at the info level.

func (*Slog) Warn

func (s *Slog) Warn(args ...any)

Warn logs a message at the warn level.

func (*Slog) Warnf

func (s *Slog) Warnf(format string, args ...any)

Warnf logs a message at the warn level.

func (*Slog) With

func (s *Slog) With(args ...any) Logger

With returns a new logger with the given fields.

func (*Slog) WithContext

func (s *Slog) WithContext(_ context.Context) *Slog

WithContext returns a logger that is bound to a specific context. Currently it just returns the same logger since we don't have context-specific fields yet.

type Zerolog

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

Zerolog is a logger that uses the zerolog package.

func NewZerolog

func NewZerolog(l zerolog.Logger) *Zerolog

NewZerolog creates a new Zerolog.

func (*Zerolog) Debug

func (z *Zerolog) Debug(args ...any)

Debug logs a message at the debug level.

func (*Zerolog) Debugf

func (z *Zerolog) Debugf(format string, args ...any)

Debugf logs a message at the debug level.

func (*Zerolog) Error

func (z *Zerolog) Error(args ...any)

Error logs a message at the error level.

func (*Zerolog) Errorf

func (z *Zerolog) Errorf(format string, args ...any)

Errorf logs a message at the error level.

func (*Zerolog) Fatal

func (z *Zerolog) Fatal(args ...any)

Fatal logs a message at the fatal level and calls os.Exit(1).

func (*Zerolog) Fatalf

func (z *Zerolog) Fatalf(format string, args ...any)

Fatalf logs a message at the fatal level and calls os.Exit(1).

func (*Zerolog) Info

func (z *Zerolog) Info(args ...any)

Info logs a message at the info level.

func (*Zerolog) Infof

func (z *Zerolog) Infof(format string, args ...any)

Infof logs a message at the info level.

func (*Zerolog) Warn

func (z *Zerolog) Warn(args ...any)

Warn logs a message at the warn level.

func (*Zerolog) Warnf

func (z *Zerolog) Warnf(format string, args ...any)

Warnf logs a message at the warn level.

func (*Zerolog) With

func (z *Zerolog) With(args ...any) Logger

With returns a new logger with the given fields.

Jump to

Keyboard shortcuts

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