Documentation
¶
Overview ¶
Package logging provides context-based logging utilities and a generic logging interface for the toolkit application.
Index ¶
- func WithContext(ctx context.Context, logger Logger) context.Context
- type Logger
- func FromContext(ctx context.Context) Logger
- func MustNewFileLogger(debug bool, filename string) Logger
- func MustNewLogger(debug bool) Logger
- func NewFileLogger(debug bool, filename string, logFormat string) (Logger, error)
- func NewLogger(debug bool) (Logger, error)
- func NewNoOpLogger() Logger
- func NewSlogLogger(s *slog.Logger, debug bool) Logger
- func NewZapLogger(s *zap.SugaredLogger, debug bool) Logger
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Logger ¶
type Logger interface { Debugw(msg string, kv ...any) Infow(msg string, kv ...any) Errorw(msg string, kv ...any) WithFields(kv ...any) Logger DebugEnabled() bool Sync() error }
Logger is an abstract logging interface for use throughout the codebase.
It is implemented by both zapLogger and slogLogger, allowing the application to switch between zap and slog backends as needed.
func FromContext ¶
FromContext retrieves the Logger from the context, or returns a no-op logger if not found.
func MustNewFileLogger ¶
MustNewFileLogger returns a file Logger or panics if creation fails.
func MustNewLogger ¶
MustNewLogger creates a new Logger or panics if creation fails.
func NewFileLogger ¶
NewFileLogger returns a Logger that writes only to the given file (overwriting it on each run). If debug is true, uses development encoder config, else production config. logFormat: "console", "json", or "slog"
func NewLogger ¶
NewLogger creates a new Logger. If debug is true, uses zap.NewDevelopment, else zap.NewProduction. By default, uses zap backend. To use slog, call NewSlogLogger directly.
func NewNoOpLogger ¶
func NewNoOpLogger() Logger
NewNoOpLogger returns a Logger that does nothing (for tests).
func NewSlogLogger ¶
NewSlogLogger returns a Logger backed by a slog.Logger. The debug flag controls DebugEnabled().
func NewZapLogger ¶
func NewZapLogger(s *zap.SugaredLogger, debug bool) Logger
NewZapLogger returns a Logger backed by a zap.SugaredLogger. The debug flag controls DebugEnabled().