logging

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Jul 27, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package logging provides structured logging for the Entire CLI using slog.

Usage:

// Initialize logger for a session (typically at session start)
if err := logging.Init(sessionID); err != nil {
    // handle error
}
defer logging.Close()

// Add context values
ctx = logging.WithComponent(ctx, "hooks")
ctx = logging.WithAgent(ctx, agentName)

// Log with context - component/agent extracted automatically
logging.Info(ctx, "hook invoked",
    slog.String("hook", hookName),
    slog.String("branch", branch),
)

Index

Constants

View Source
const LogLevelEnvVar = "ENTIRE_LOG_LEVEL"

LogLevelEnvVar is the environment variable that controls log level.

View Source
const LogsDir = ".entire/logs"

LogsDir is the directory where log files are stored (relative to repo root).

Variables

This section is empty.

Functions

func Close

func Close()

Close closes the log file if one is open. Flushes any buffered data before closing. Safe to call multiple times.

func Debug

func Debug(ctx context.Context, msg string, attrs ...any)

Debug logs at DEBUG level with context values automatically extracted.

func Error

func Error(ctx context.Context, msg string, attrs ...any)

Error logs at ERROR level with context values automatically extracted.

func Info

func Info(ctx context.Context, msg string, attrs ...any)

Info logs at INFO level with context values automatically extracted.

func Init

func Init(ctx context.Context, sessionID string) error

Init initializes the logger for a session, writing JSON logs to .entire/logs/entire.log.

If sessionID is non-empty, it is stored as an slog attribute on every log line for filtering. If the log file cannot be created, falls back to stderr. Log level is controlled by ENTIRE_LOG_LEVEL environment variable.

func SetLogLevelGetter

func SetLogLevelGetter(getter func() string)

SetLogLevelGetter sets a callback function to get the log level from settings. This allows the logging package to read settings without a circular dependency. The callback is only used if ENTIRE_LOG_LEVEL env var is not set.

func Warn

func Warn(ctx context.Context, msg string, attrs ...any)

Warn logs at WARN level with context values automatically extracted.

func WithAgent

func WithAgent(ctx context.Context, agentName types.AgentName) context.Context

WithAgent adds an agent name to the context. Agent names identify the AI agent generating activity (e.g., "claude-code", "cursor", "aider").

func WithComponent

func WithComponent(ctx context.Context, component string) context.Context

WithComponent adds a component name to the context. Component names help identify the subsystem generating logs (e.g., "hooks", "strategy", "session").

Types

This section is empty.

Jump to

Keyboard shortcuts

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