logging

package
v0.3.20 Latest Latest
Warning

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

Go to latest
Published: Jan 1, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package logging provides structured logging with multiple output formats and levels.

Index

Constants

View Source
const (
	EventSessionStart   = "session_start"
	EventSessionEnd     = "session_end"
	EventAPIRequest     = "api_request"
	EventAPIResponse    = "api_response"
	EventToolExecution  = "tool_execution"
	EventToolApproval   = "tool_approval"
	EventStreamStart    = "stream_start"
	EventStreamComplete = "stream_complete"
)

Event types for session logging

Variables

This section is empty.

Functions

func CleanupOldSessions added in v0.3.6

func CleanupOldSessions(sessionsDir string, maxAge time.Duration) (int, error)

CleanupOldSessions removes session logs older than maxAge This should be called at startup to prevent disk bloat

func Debug

func Debug(msg string, args ...any)

Debug logs a debug message using the global logger

func DebugWith

func DebugWith(msg string, args ...any)

DebugWith logs a debug message with attributes using the global logger

func Error

func Error(msg string, args ...any)

Error logs an error message using the global logger

func ErrorWith

func ErrorWith(msg string, args ...any)

ErrorWith logs an error message with attributes using the global logger

func ErrorWithErr

func ErrorWithErr(msg string, err error, args ...any)

ErrorWithErr logs an error with an error object using the global logger

func Info

func Info(msg string, args ...any)

Info logs an info message using the global logger

func InfoWith

func InfoWith(msg string, args ...any)

InfoWith logs an info message with attributes using the global logger

func SetGlobalLogger

func SetGlobalLogger(logger *Logger)

SetGlobalLogger sets the global logger instance

func TruncateParams added in v0.3.6

func TruncateParams(params map[string]interface{}, maxLen int) map[string]interface{}

TruncateParams creates a copy of params with large values truncated

func TruncateValue added in v0.3.6

func TruncateValue(s string, maxLen int) string

TruncateValue truncates a string value if it exceeds maxLen Used to prevent excessively large log entries

func Warn

func Warn(msg string, args ...any)

Warn logs a warning message using the global logger

func WarnWith

func WarnWith(msg string, args ...any)

WarnWith logs a warning message with attributes using the global logger

func WithConversationID

func WithConversationID(ctx context.Context, id string) context.Context

WithConversationID adds a conversation ID to the context

func WithRequestID

func WithRequestID(ctx context.Context, id string) context.Context

WithRequestID adds a request ID to the context

Types

type Config

type Config struct {
	Level     Level
	Format    Format
	Writer    io.Writer
	LogFile   string
	AddSource bool
}

Config holds logger configuration

type Format

type Format int

Format represents log output format

const (
	// FormatText outputs logs in plain text format
	FormatText Format = iota
	// FormatJSON outputs logs in JSON format
	FormatJSON
)

type Level

type Level int

Level represents log severity levels

const (
	// LevelDebug enables debug-level logging
	LevelDebug Level = iota
	// LevelInfo enables info-level logging
	LevelInfo
	// LevelWarn enables warning-level logging
	LevelWarn
	// LevelError enables error-level logging
	LevelError
)

func LevelFromString

func LevelFromString(s string) Level

LevelFromString converts a string to a log level

type Logger

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

Logger wraps slog.Logger with additional functionality

func Default

func Default() *Logger

Default returns the global logger instance

func NewLogger

func NewLogger(cfg Config) *Logger

NewLogger creates a new logger with the given configuration

func NewLoggerWithFile

func NewLoggerWithFile(cfg Config) (*Logger, error)

NewLoggerWithFile creates a logger that writes to a file and optionally to writer

func (*Logger) Close

func (l *Logger) Close() error

Close closes any open file handles

func (*Logger) Debug

func (l *Logger) Debug(msg string, args ...any)

Debug logs a debug message

func (*Logger) DebugWith

func (l *Logger) DebugWith(msg string, args ...any)

DebugWith logs a debug message with structured attributes

func (*Logger) DebugWithContext

func (l *Logger) DebugWithContext(ctx context.Context, msg string, args ...any)

DebugWithContext logs a debug message with context metadata

func (*Logger) Error

func (l *Logger) Error(msg string, args ...any)

Error logs an error message

func (*Logger) ErrorWith

func (l *Logger) ErrorWith(msg string, args ...any)

ErrorWith logs an error message with structured attributes

func (*Logger) ErrorWithContext

func (l *Logger) ErrorWithContext(ctx context.Context, msg string, args ...any)

ErrorWithContext logs an error message with context metadata

func (*Logger) ErrorWithErr

func (l *Logger) ErrorWithErr(msg string, err error, args ...any)

ErrorWithErr logs an error message with an error object

func (*Logger) Info

func (l *Logger) Info(msg string, args ...any)

Info logs an info message

func (*Logger) InfoWith

func (l *Logger) InfoWith(msg string, args ...any)

InfoWith logs an info message with structured attributes

func (*Logger) InfoWithContext

func (l *Logger) InfoWithContext(ctx context.Context, msg string, args ...any)

InfoWithContext logs an info message with context metadata

func (*Logger) Warn

func (l *Logger) Warn(msg string, args ...any)

Warn logs a warning message

func (*Logger) WarnWith

func (l *Logger) WarnWith(msg string, args ...any)

WarnWith logs a warning message with structured attributes

func (*Logger) WarnWithContext

func (l *Logger) WarnWithContext(ctx context.Context, msg string, args ...any)

WarnWithContext logs a warning message with context metadata

type SessionEvent added in v0.3.6

type SessionEvent struct {
	Timestamp time.Time              `json:"timestamp"`
	SessionID string                 `json:"session_id"`
	EventType string                 `json:"event_type"`
	Data      map[string]interface{} `json:"data,omitempty"`
}

SessionEvent represents a loggable event in a session

type SessionLogger added in v0.3.6

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

SessionLogger handles per-session JSONL logging

func NewSessionLogger added in v0.3.6

func NewSessionLogger(jeffDir, sessionID string) (*SessionLogger, error)

NewSessionLogger creates a new session logger for the given session ID It creates the sessions directory if it doesn't exist

func (*SessionLogger) Close added in v0.3.6

func (sl *SessionLogger) Close() error

Close closes the session log file

func (*SessionLogger) LogAPIRequest added in v0.3.6

func (sl *SessionLogger) LogAPIRequest(messageCount, toolsCount, maxTokens int) error

LogAPIRequest logs an API request event

func (*SessionLogger) LogAPIResponse added in v0.3.6

func (sl *SessionLogger) LogAPIResponse(stopReason string, inputTokens, outputTokens int) error

LogAPIResponse logs an API response event

func (*SessionLogger) LogEvent added in v0.3.6

func (sl *SessionLogger) LogEvent(eventType string, data map[string]interface{}) error

LogEvent writes an event to the session log

func (*SessionLogger) LogSessionEnd added in v0.3.6

func (sl *SessionLogger) LogSessionEnd() error

LogSessionEnd logs the session end event

func (*SessionLogger) LogSessionStart added in v0.3.6

func (sl *SessionLogger) LogSessionStart(model string, conversationID string, resumed bool) error

LogSessionStart logs the session start event

func (*SessionLogger) LogToolApproval added in v0.3.6

func (sl *SessionLogger) LogToolApproval(toolName, toolID string, approved bool, reason string) error

LogToolApproval logs a tool approval decision

func (*SessionLogger) LogToolExecution added in v0.3.6

func (sl *SessionLogger) LogToolExecution(toolName, toolID string, approved, success bool, durationMs int64, errMsg string) error

LogToolExecution logs a tool execution event

func (*SessionLogger) SessionID added in v0.3.6

func (sl *SessionLogger) SessionID() string

SessionID returns the session ID

Jump to

Keyboard shortcuts

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