logging

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2026 License: MIT Imports: 33 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	LevelNotSet   = 0
	LevelDebug    = 10
	LevelInfo     = 20
	LevelWarning  = 30
	LevelError    = 40
	LevelCritical = 50
)

Variables

View Source
var (
	RedactingHandler     func(next slog.Handler) slog.Handler
	RedactSensitiveText  func(text string) string
	ResolveProfilePolicy func(home string)
)

Hooks pkg/tools sets in an init so formatters and stdio redact the way agent.redact does

View Source
var ComponentPrefixes = map[string][]string{
	"gateway": {"gateway", "gatewayrun", "gatewayapi"},
	"agent":   {"agent", "provider", "providerregistry", "memory", "monitoring", "lsp", "i18n", "pet", "trajectorycompressor", "batchrun"},
	"tools":   {"tools", "media", "mcp", "browser", "codeexec", "skills", "gateway/messagetools"},
	"cli":     {"cmd/icebath", "app", "commands", "activesessions", "gatewaycli", "goals", "kanban", "selfupdate", "plugins", "profiles", "setupflow"},
	"cron":    {"cron"},
	"gui":     {"tuiserver", "tuigateway", "tui"},
}

Packages of each component, gating component logs and logs --component

View Source
var LogFiles = map[string]string{
	"agent": "agent.log", "errors": "errors.log", "gateway": "gateway.log", "update": "update.log", "mcp": "mcp-stderr.log",
}

Known log files by the name icebath logs takes

View Source
var LogTiers = map[string]string{"update": linktier.Extras}

Tier whose code writes a log, update.log being the self updater's, absent for core logs

View Source
var RootHomeLogs = []string{"update"}

Logs the root home holds whatever profile is active, in name order

Functions

func AddGatewayStderrHandler

func AddGatewayStderrHandler(level int) error

Adds the gateway console handler at level to the root logger, lowering the root level to reach it

func ClearSessionContext

func ClearSessionContext()

Stops tagging the calling goroutine's records with a session id

func DrainLogQueue

func DrainLogQueue(timeout time.Duration)

Drains the queue for a hard exit, waiting at most timeout for a listener wedged on the rotation lock

func EnableProfileLogRouting

func EnableProfileLogRouting(profileHomes []string) (bool, error)

Replaces the queued file handlers with profile routers over homes, true when routing is or already was on

func FlushLogQueue

func FlushLogQueue()

Blocks until every queued record is written, then resumes the listener

func InComponent

func InComponent(name string, packages []string) bool

Whether a logger name is one of the packages or a package below one of them

func InstallSlogBridge

func InstallSlogBridge()

Routes slog through the logger hierarchy from process start, so a record before setup meets the last resort handler

func LevelName

func LevelName(level int) string

Name of a numeric level, Level N for one without a name

func LogFilePath

func LogFilePath(ctx context.Context, name string) (string, bool)

Where a named log lives without checking it exists, false for an unknown name

func RedactDetachedStdio

func RedactDetachedStdio() error

Routes stdout and stderr of a detached process through secret redaction, once per stream

func ReleaseProfileLogHandlers

func ReleaseProfileLogHandlers(profileHome string) (int, error)

Closes this process's routed log files below a profile home before the profile is removed

func ResetQueuedHandlers

func ResetQueuedHandlers()

Tears down the queue, the listener and every queued handler

func SetSessionContext

func SetSessionContext(sessionID string)

Tags every record the calling goroutine logs with the session id

func SetupHomeLogging

func SetupHomeLogging(h, mode string) error

Configures the log files of home for mode, the setup_logging call a worker process makes at startup

func SetupLogging

func SetupLogging(ctx context.Context, o Options) (string, error)

Configures the log files of a home and returns its logs directory, a second call a no op unless forced

func SetupVerboseLogging

func SetupVerboseLogging() error

Adds the DEBUG console handler of verbose mode once

func Shutdown

func Shutdown()

Stops the log listener after it writes every queued record, then closes every handler newest first

Types

type Filter

type Filter interface {
	Filter(rec *Record) bool
}

Gate deciding whether a handler takes a record

type Formatter

type Formatter struct {
	// contains filtered or unexported fields
}

Renders records through a {field} template, redacting the whole line when built with the redaction hook

func GatewayStderrFormatter

func GatewayStderrFormatter() (*Formatter, error)

Redacting formatter of the gateway stderr stream

func LogFileFormatter

func LogFileFormatter() (*Formatter, error)

Redacting formatter the agent, errors and gateway log files write their lines through

func NewFormatter

func NewFormatter(format, datefmt string) *Formatter

Formatter for a {field} template and strftime date format, the default message format when empty

func (*Formatter) Format

func (f *Formatter) Format(ctx context.Context, rec *Record) (string, error)

Formatted line for rec, redacted under the profile policy ctx carries

type Handler

type Handler interface {
	Handle(ctx context.Context, rec *Record) bool
	Level() int
	Close() error
}

Destination for records, Handle applying the handler's filters before it emits

func NewRedactingRotatingFileHandler

func NewRedactingRotatingFileHandler(ctx context.Context, path string, maxBytes float64, backupCount int, format string) (Handler, error)

Size rotated log file handler whose records pass the redacting formatter with the given format

type Logger

type Logger struct {
	// contains filtered or unexported fields
}

Named node of the package logger hierarchy with its level, handlers and propagation switch

func GetLogger

func GetLogger(name string) *Logger

Logger for a slash separated package name, the root logger for an empty name or root

func (*Logger) AddHandler

func (l *Logger) AddHandler(h Handler)

Attaches a handler to this logger

func (*Logger) Debug

func (l *Logger) Debug(msg string)

Logs msg at DEBUG

func (*Logger) EffectiveLevel

func (l *Logger) EffectiveLevel() int

First level set walking up the hierarchy, zero when none is set

func (*Logger) Error

func (l *Logger) Error(msg string)

Logs msg at ERROR

func (*Logger) Exception

func (l *Logger) Exception(msg string, err error)

Logs msg at ERROR with the error text below it, the error carried on the record for filters

func (*Logger) Handlers

func (l *Logger) Handlers() []Handler

Handlers attached directly to this logger

func (*Logger) Info

func (l *Logger) Info(msg string)

Logs msg at INFO

func (*Logger) IsEnabledFor

func (l *Logger) IsEnabledFor(level int) bool

Reports whether a record at level passes this logger's effective level

func (*Logger) Level

func (l *Logger) Level() int

Level set on this logger, zero when it defers to its ancestors

func (*Logger) Log

func (l *Logger) Log(level int, msg string)

Logs msg at level

func (*Logger) LogContext

func (l *Logger) LogContext(ctx context.Context, level int, msg string)

Logs msg at level with the record attributes resolved from ctx

func (*Logger) Name

func (l *Logger) Name() string

Package name of the logger

func (*Logger) RemoveHandler

func (l *Logger) RemoveHandler(h Handler)

Detaches a handler from this logger

func (*Logger) SetLevel

func (l *Logger) SetLevel(level int)

Sets the logger level and refreshes the cheapest level any logger accepts

func (*Logger) SetPropagate

func (l *Logger) SetPropagate(on bool)

Turns propagation of records to ancestor handlers on or off

func (*Logger) Slog

func (l *Logger) Slog() *slog.Logger

slog logger whose records reach this logger through the bridge

func (*Logger) Warning

func (l *Logger) Warning(msg string)

Logs msg at WARNING

type Options

type Options struct {
	Home        string
	LogLevel    string
	MaxSizeMB   int
	BackupCount int
	Mode        string
	Force       bool
}

Options of SetupLogging, zero values deferring to config.yaml logging and the built in defaults

type Record

type Record struct {
	Name       string
	Levelno    int
	Levelname  string
	Msg        string
	Created    time.Time
	SessionTag string
	Home       string
	Thread     uint64
	PC         uintptr
	// Error logged with the record, its text already below Msg
	ExcInfo error
}

One log event with the attributes the formatters render

func MakeRecord

func MakeRecord(ctx context.Context, name string, level int, msg string) *Record

Record the log record factory builds now for the calling goroutine

type StreamHandler

type StreamHandler interface {
	Handler
	SetLevel(level int)
	AddFilter(f Filter)
	Formatter() *Formatter
}

Stream handler whose filters and formatter a caller sets up

func NewRedactingStderrHandler

func NewRedactingStderrHandler(format, datefmt string) (StreamHandler, error)

Handler writing records to stderr through a redacting formatter of the given format

Jump to

Keyboard shortcuts

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