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 ¶
FromContext returns the logger attached to ctx, or slog.Default() if none is set. Callers should never see a nil logger.
func Install ¶
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 ¶
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.
Types ¶
This section is empty.