log

package
v0.0.0-...-5ed4770 Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package log provides context-aware structured logging built on log/slog.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func From

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

From retrieves the logger from context. Returns slog.Default() if no logger is stored.

func Inject

func Inject(ctx context.Context, userID, connID, convID string) context.Context

Inject creates a new logger with request-scoped fields and stores it in context. Call once per connection (e.g., WebSocket handshake, HTTP middleware). All subsequent From(ctx) calls will include these fields.

func InjectLogger

func InjectLogger(ctx context.Context, l *slog.Logger) context.Context

InjectLogger stores a logger in the context. Use From(ctx) to retrieve it.

func New

func New(base *slog.Logger) *slog.Logger

New wraps a base logger with caller info injection. Call this in main.go after config.NewLogger():

base := config.NewLogger(logFile)
logger := log.New(base)
ctx := log.InjectLogger(context.Background(), logger)

func NewCallerHandler

func NewCallerHandler(inner slog.Handler) slog.Handler

NewCallerHandler creates a handler that adds caller info to each log record. The inner handler must have AddSource=false (callerHandler takes over source info).

Types

This section is empty.

Jump to

Keyboard shortcuts

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