Documentation
¶
Overview ¶
Package logging provides structured logging with multiple output formats and levels.
Index ¶
- Constants
- func CleanupOldSessions(sessionsDir string, maxAge time.Duration) (int, error)
- func Debug(msg string, args ...any)
- func DebugWith(msg string, args ...any)
- func Error(msg string, args ...any)
- func ErrorWith(msg string, args ...any)
- func ErrorWithErr(msg string, err error, args ...any)
- func Info(msg string, args ...any)
- func InfoWith(msg string, args ...any)
- func SetGlobalLogger(logger *Logger)
- func TruncateParams(params map[string]interface{}, maxLen int) map[string]interface{}
- func TruncateValue(s string, maxLen int) string
- func Warn(msg string, args ...any)
- func WarnWith(msg string, args ...any)
- func WithConversationID(ctx context.Context, id string) context.Context
- func WithRequestID(ctx context.Context, id string) context.Context
- type Config
- type Format
- type Level
- type Logger
- func (l *Logger) Close() error
- func (l *Logger) Debug(msg string, args ...any)
- func (l *Logger) DebugWith(msg string, args ...any)
- func (l *Logger) DebugWithContext(ctx context.Context, msg string, args ...any)
- func (l *Logger) Error(msg string, args ...any)
- func (l *Logger) ErrorWith(msg string, args ...any)
- func (l *Logger) ErrorWithContext(ctx context.Context, msg string, args ...any)
- func (l *Logger) ErrorWithErr(msg string, err error, args ...any)
- func (l *Logger) Info(msg string, args ...any)
- func (l *Logger) InfoWith(msg string, args ...any)
- func (l *Logger) InfoWithContext(ctx context.Context, msg string, args ...any)
- func (l *Logger) Warn(msg string, args ...any)
- func (l *Logger) WarnWith(msg string, args ...any)
- func (l *Logger) WarnWithContext(ctx context.Context, msg string, args ...any)
- type SessionEvent
- type SessionLogger
- func (sl *SessionLogger) Close() error
- func (sl *SessionLogger) LogAPIRequest(messageCount, toolsCount, maxTokens int) error
- func (sl *SessionLogger) LogAPIResponse(stopReason string, inputTokens, outputTokens int) error
- func (sl *SessionLogger) LogEvent(eventType string, data map[string]interface{}) error
- func (sl *SessionLogger) LogSessionEnd() error
- func (sl *SessionLogger) LogSessionStart(model string, conversationID string, resumed bool) error
- func (sl *SessionLogger) LogToolApproval(toolName, toolID string, approved bool, reason string) error
- func (sl *SessionLogger) LogToolExecution(toolName, toolID string, approved, success bool, durationMs int64, ...) error
- func (sl *SessionLogger) SessionID() string
Constants ¶
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
CleanupOldSessions removes session logs older than maxAge This should be called at startup to prevent disk bloat
func ErrorWithErr ¶
ErrorWithErr logs an error with an error object using the global logger
func SetGlobalLogger ¶
func SetGlobalLogger(logger *Logger)
SetGlobalLogger sets the global logger instance
func TruncateParams ¶ added in v0.3.6
TruncateParams creates a copy of params with large values truncated
func TruncateValue ¶ added in v0.3.6
TruncateValue truncates a string value if it exceeds maxLen Used to prevent excessively large log entries
func WithConversationID ¶
WithConversationID adds a conversation ID to the context
Types ¶
type Level ¶
type Level int
Level represents log severity levels
func LevelFromString ¶
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 NewLoggerWithFile ¶
NewLoggerWithFile creates a logger that writes to a file and optionally to writer
func (*Logger) DebugWithContext ¶
DebugWithContext logs a debug message with context metadata
func (*Logger) ErrorWithContext ¶
ErrorWithContext logs an error message with context metadata
func (*Logger) ErrorWithErr ¶
ErrorWithErr logs an error message with an error object
func (*Logger) InfoWithContext ¶
InfoWithContext logs an info 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