logging

package
v0.10.1 Latest Latest
Warning

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

Go to latest
Published: Aug 18, 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.

It also drops the logger itself, so a caller that keeps logging afterwards falls back to slog.Default() rather than writing into a handler bound to the buffer we just closed. That handler holds the *bufio.Writer by value (see createLogger), so leaving it in place would silently swallow every later line: short writes sit in an orphaned buffer nobody flushes, and once it fills the underlying file is already closed. Commands that Close mid-run and keep working should call EnsureInitialized again rather than rely on the fallback.

func Debug

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

Debug logs at DEBUG level with context values automatically extracted.

func EnsureInitialized added in v0.10.1

func EnsureInitialized(ctx context.Context) func()

EnsureInitialized routes logging to .entire/logs/ unless it is already initialized, and returns a function that tears down only what it set up.

It exists for code that emits logging.* calls from a plain command rather than a hook. Without an initialized logger, log() falls back to slog.Default(), which prints internal structured lines straight onto the user's terminal in the middle of command output — see the same hazard called out at the Init call sites in setup.go and investigate/cmd.go.

Unlike Init it is a no-op when a logger already exists, so a caller reachable from a hook cannot close the hook's log file out from under it. Like Init, it CREATES .entire/logs/, so call it only once the command is committed to doing work in an Entire-enabled repository.

Scope the returned cleanup to everything the command still has to log, not just the call that needed logging in the first place: it closes the file, so anything logged after it runs goes back to the terminal via slog.Default().

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