logger

package
v1.11.0 Latest Latest
Warning

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

Go to latest
Published: Jul 11, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(cfg Config) (*slog.Logger, io.Closer, error)

New constructs a *slog.Logger. Writer resolution priority:

  1. cfg.Output (explicit override — useful for tests)
  2. file in cfg.LogDir named "{agentId}+{timestamp}.log"
  3. os.Stdout

The returned io.Closer owns the log file when New opened one (nil otherwise) — the agent must Close it on shutdown. Leaving it open merely leaked an fd on unix, but on Windows an open log file blocks deletion of its directory (TempDir cleanup, space removal, rotation).

func OfAgent

func OfAgent(cfg *config.Config, parentID, agentID string) (*slog.Logger, io.Closer, error)

OfAgent constructs a logger using the supplied runtime configuration. cfg may be nil — the logger falls back to stdout in that case (useful for tests). The io.Closer follows New's contract.

Types

type Config

type Config struct {
	Level   string
	Format  string
	AgentID string    // required: identifies the agent, used in log filename
	LogDir  string    // optional: if empty, falls back to os.Stdout
	Output  io.Writer // optional: override resolved writer (useful in tests)
}

Config holds logger configuration. Output is optional — resolved at construction time based on LogDir + AgentID.

Jump to

Keyboard shortcuts

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