Files
core/logz/doc.go
T

28 lines
1.0 KiB
Go
Raw Normal View History

// Package logz provides a structured, leveled logger backed by the standard
// library's log/slog package.
//
// logz.New returns a logging.Logger (from contracts). No concrete type is
// exported — callers depend on the interface, not the implementation.
//
// Error enrichment: when an error passed to Logger.Error implements
// errs.CodedError or errs.ContextualError (from contracts/errs), the
// corresponding fields are automatically appended to the log record without
// either package importing the other.
//
// Context enrichment: WithRequestID, WithField, and WithFields store values
// in context.Context. Logger.WithContext reads them back and attaches
// request_id and any extra fields to every subsequent log record.
//
// Usage:
//
// logger := logz.New(logz.Config{
// Level: slog.LevelDebug,
// JSON: true,
// StaticArgs: []any{"service", "api"},
// })
//
// ctx = logz.WithRequestID(ctx, requestID)
// reqLogger := logger.WithContext(ctx)
// reqLogger.Info("handling request", "path", r.URL.Path)
package logz