logging

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Jul 23, 2025 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package logging provides context-based logging utilities and a generic logging interface for the toolkit application.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WithContext

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

WithContext returns a new context with the provided Logger attached.

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

func FromContext(ctx context.Context) Logger

FromContext retrieves the Logger from the context, or returns a no-op logger if not found.

func MustNewFileLogger

func MustNewFileLogger(debug bool, filename string) Logger

MustNewFileLogger returns a file Logger or panics if creation fails.

func MustNewLogger

func MustNewLogger(debug bool) Logger

MustNewLogger creates a new Logger or panics if creation fails.

func NewFileLogger

func NewFileLogger(debug bool, filename string, logFormat string) (Logger, error)

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

func NewLogger(debug bool) (Logger, error)

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

func NewSlogLogger(s *slog.Logger, debug bool) Logger

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().

Jump to

Keyboard shortcuts

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