logger

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package logger provides structured logging with slog, tint-based human-readable output, and OpenTelemetry trace correlation.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Debug

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

Debug logs at LevelDebug using the logger from context.

func Error

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

Error logs at LevelError using the logger from context.

func FromContext

func FromContext(ctx context.Context) *slog.Logger

FromContext extracts the logger from context or returns the default logger.

func Info

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

Info logs at LevelInfo using the logger from context.

func New

func New(cfg Config, opts ...Option) *slog.Logger

New creates a configured slog.Logger instance based on Config and Options.

func Warn

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

Warn logs at LevelWarn using the logger from context.

func WithContext

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

WithContext returns a new context carrying the given logger.

Types

type Config

type Config struct {
	Format string `toml:"format" env:"FORMAT" env-default:"text" comment:"Log format: text or json"`
	Level  string `toml:"level" env:"LEVEL" env-default:"info" comment:"Log level: debug, info, warn, error"`
}

Config defines logger configuration settings.

type Option

type Option func(slog.Handler) slog.Handler

Option decorates the base slog.Handler.

func WithTracing

func WithTracing() Option

WithTracing returns an Option that injects trace_id and span_id into log records.

Jump to

Keyboard shortcuts

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