logging

package
v1.3.1 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package logging provides a thin wrapper around log/slog that reads its level, format, and destination from the AgentManager config.

The stdlib's log/slog is the primary API — callers should use FromContext(ctx) to obtain a *slog.Logger and call its methods directly (Debug/Info/Warn/Error, With, ...). This package only adds:

  • New(cfg): construct a logger configured from cfg.Logging.
  • WithContext/FromContext: plumb the logger through a context.
  • Install: swap slog.Default() to the configured logger, useful in main so libraries that reach for slog.Default also see the configuration.

No custom Info/Warn/Error wrappers — those add no value over slog and make it harder to grep for callers.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FromContext

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

FromContext returns the logger attached to ctx, or slog.Default() if none is set. Callers should never see a nil logger.

func Install

func Install(logger *slog.Logger)

Install swaps slog.Default() to logger so libraries that reach for the default logger (rather than taking one via DI or context) also benefit from the configured level/format. Typical use is once at program start after New.

func New

func New(cfg *config.Config) *slog.Logger

New constructs a *slog.Logger configured from cfg.Logging.

  • Level: "debug" | "info" | "warn" | "error" (case-insensitive). Invalid values fall back to info — never error, so a misconfigured user config does not prevent startup.
  • Format: "json" | "text" (case-insensitive). Default is text.
  • File: if non-empty, logs are appended to the file. Failure to open the file falls back to stderr and an early warn is emitted so the operator can see it.

A nil cfg or nil cfg.Logging returns a sensible default (info, text, stderr) rather than panicking — handy in tests and early startup.

func WithContext

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

WithContext returns ctx carrying logger. A nil logger is a no-op to keep middleware chains safe.

Types

This section is empty.

Jump to

Keyboard shortcuts

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