Documentation
¶
Overview ¶
Package logging provides structured logging via Go's log/slog. Production: JSON output. Development: text output with colors.
Usage:
logger := logging.New("json", "info") // production
logger := logging.New("text", "debug") // development
logger.Info("event ingested", "event_id", id, "source", src)
Index ¶
- func GetRequestID(ctx context.Context) string
- func New(format, level string) *slog.Logger
- func NewWithOutput(format, level string, w io.Writer) *slog.Logger
- func RequestID() string
- func RequestIDMiddleware(logger *slog.Logger, next http.Handler) http.Handler
- func WithComponent(logger *slog.Logger, component string) *slog.Logger
- func WithRequestID(ctx context.Context, id string) context.Context
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetRequestID ¶
GetRequestID extracts the request ID from context (empty if not set).
func New ¶
New creates a structured logger. format: "json" (production) or "text" (development). level: "debug", "info", "warn", "error".
func NewWithOutput ¶
NewWithOutput creates a logger writing to the given writer.
func RequestIDMiddleware ¶
RequestIDMiddleware injects a unique request ID into each request context and logs request start/end with duration.
func WithComponent ¶
WithComponent returns a logger with a "component" attribute.
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.