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
- func AgentFromContext(ctx context.Context) string
- func Close()
- func ComponentFromContext(ctx context.Context) string
- func Debug(ctx context.Context, msg string, attrs ...any)
- func Error(ctx context.Context, msg string, attrs ...any)
- func Info(ctx context.Context, msg string, attrs ...any)
- func Init(sessionID string) error
- func LogDuration(ctx context.Context, level slog.Level, msg string, start time.Time, ...)
- func ParentSessionIDFromContext(ctx context.Context) string
- func SessionIDFromContext(ctx context.Context) string
- func SetLogLevelGetter(getter func() string)
- func ToolCallIDFromContext(ctx context.Context) string
- func Warn(ctx context.Context, msg string, attrs ...any)
- func WithAgent(ctx context.Context, agentName agent.AgentName) context.Context
- func WithComponent(ctx context.Context, component string) context.Context
- func WithParentSession(ctx context.Context, parentSessionID string) context.Context
- func WithSession(ctx context.Context, sessionID string) context.Context
- func WithToolCall(ctx context.Context, toolCallID string) context.Context
Constants ¶
const LogLevelEnvVar = "ENTIRE_LOG_LEVEL"
LogLevelEnvVar is the environment variable that controls log level.
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 ¶
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 ¶
ComponentFromContext extracts the component name from the context. Returns empty string if not set.
func Init ¶
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 LogDuration ¶
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 ¶
ParentSessionIDFromContext extracts the parent session ID from the context. Returns empty string if not set.
func SessionIDFromContext ¶
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 ¶
ToolCallIDFromContext extracts the tool call ID from the context. Returns empty string if not set.
func WithAgent ¶
WithAgent adds an agent name to the context. Agent names identify the AI agent generating activity (e.g., "claude-code", "cursor", "aider").
func WithComponent ¶
WithComponent adds a component name to the context. Component names help identify the subsystem generating logs (e.g., "hooks", "strategy", "session").
func WithParentSession ¶
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 ¶
WithSession adds a session ID to the context. If the context already has a session ID, it becomes the parent session ID.
Types ¶
This section is empty.