logging

package
v0.3.11 Latest Latest
Warning

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

Go to latest
Published: Feb 5, 2026 License: MIT Imports: 13 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.WithSession(ctx, sessionID)
ctx = logging.WithToolCall(ctx, toolCallID)

// Log with context - session/tool IDs 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 AgentFromContext

func AgentFromContext(ctx context.Context) string

AgentFromContext extracts the agent name from the context. Returns empty string if not set.

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 ComponentFromContext

func ComponentFromContext(ctx context.Context) string

ComponentFromContext extracts the component name from the context. Returns empty string if not set.

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(sessionID string) error

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

If the log file cannot be created, falls back to stderr. Log level is controlled by ENTIRE_LOG_LEVEL environment variable.

func LogDuration

func LogDuration(ctx context.Context, level slog.Level, msg string, start time.Time, attrs ...any)

LogDuration logs a message with duration_ms calculated from the start time. The level parameter specifies the log level (use slog.LevelDebug, slog.LevelInfo, etc). Designed for use with defer:

defer logging.LogDuration(ctx, slog.LevelInfo, "operation completed", time.Now())

Or with additional attrs:

defer logging.LogDuration(ctx, slog.LevelDebug, "hook executed", start,
    slog.String("hook", hookName),
    slog.Bool("success", true),
)

func ParentSessionIDFromContext

func ParentSessionIDFromContext(ctx context.Context) string

ParentSessionIDFromContext extracts the parent session ID from the context. Returns empty string if not set.

func SessionIDFromContext

func SessionIDFromContext(ctx context.Context) string

SessionIDFromContext extracts the session ID from the context. Returns empty string if not set.

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 ToolCallIDFromContext

func ToolCallIDFromContext(ctx context.Context) string

ToolCallIDFromContext extracts the tool call ID from the context. Returns empty string if 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 agent.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").

func WithParentSession

func WithParentSession(ctx context.Context, parentSessionID string) context.Context

WithParentSession explicitly sets the parent session ID. Use this when you need to set the parent explicitly rather than having it inferred from an existing session.

func WithSession

func WithSession(ctx context.Context, sessionID string) context.Context

WithSession adds a session ID to the context. If the context already has a session ID, it becomes the parent session ID.

func WithToolCall

func WithToolCall(ctx context.Context, toolCallID string) context.Context

WithToolCall adds a tool call ID to the context.

Types

This section is empty.

Jump to

Keyboard shortcuts

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