logging

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 31, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetRequestID

func GetRequestID(ctx context.Context) string

GetRequestID extracts the request ID from context (empty if not set).

func New

func New(format, level string) *slog.Logger

New creates a structured logger. format: "json" (production) or "text" (development). level: "debug", "info", "warn", "error".

func NewWithOutput

func NewWithOutput(format, level string, w io.Writer) *slog.Logger

NewWithOutput creates a logger writing to the given writer.

func RequestID

func RequestID() string

RequestID generates a short unique request ID.

func RequestIDMiddleware

func RequestIDMiddleware(logger *slog.Logger, next http.Handler) http.Handler

RequestIDMiddleware injects a unique request ID into each request context and logs request start/end with duration.

func WithComponent

func WithComponent(logger *slog.Logger, component string) *slog.Logger

WithComponent returns a logger with a "component" attribute.

func WithRequestID

func WithRequestID(ctx context.Context, id string) context.Context

WithRequestID returns a context with a request ID attached.

Types

This section is empty.

Jump to

Keyboard shortcuts

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