logger

package
v0.0.55 Latest Latest
Warning

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

Go to latest
Published: Aug 8, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package logger provides session logging for pi-go. Logs are written to ~/.pi-go/log/yyyy-mm-dd/session-HH-MM-SS.log

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HTTPSink added in v0.0.51

func HTTPSink(l *Logger) func(httplog.Entry)

HTTPSink adapts a Logger to httplog's sink signature, so --trace-http entries land in the same JSONL session file as everything else.

The dependency runs one way only — httplog knows nothing about Logger — which is what lets the provider transports emit traces without importing the logger they cannot reach at construction time.

Returns nil for a nil Logger so the caller can install the result unconditionally; httplog.SetSink(nil) simply detaches.

Types

type Entry

type Entry struct {
	Time    string `json:"time"`
	Type    string `json:"type"`              // "user", "llm_text", "thinking", "tool_call", "tool_result", "error", "info", "http_request", "http_response"
	Agent   string `json:"agent,omitempty"`   // agent name (for subagents)
	Tool    string `json:"tool,omitempty"`    // tool name
	Content string `json:"content,omitempty"` // text content, error message, or HTTP body
	Args    any    `json:"args,omitempty"`    // tool call arguments
	Session string `json:"session,omitempty"` // session ID (logged once at start)
	Model   string `json:"model,omitempty"`   // model name (logged once at start)

	// HTTP trace fields, set only on "http_request"/"http_response" entries
	// written under --trace-http. They are part of Entry rather than a
	// separate record type so the transport trace interleaves with the tool
	// calls and model output it caused, in one chronologically ordered file.
	Exchange  uint64              `json:"exchange,omitempty"`  // correlates a request with its response
	Method    string              `json:"method,omitempty"`    // HTTP method
	URL       string              `json:"url,omitempty"`       // full request URL
	Proto     string              `json:"proto,omitempty"`     // e.g. "HTTP/2.0"
	Status    int                 `json:"status,omitempty"`    // response status code
	Headers   map[string][]string `json:"headers,omitempty"`   // credential values already masked
	Truncated bool                `json:"truncated,omitempty"` // body was cut at the cap
	DurationM int64               `json:"duration_ms,omitempty"`
}

Entry represents a single log entry.

type Logger

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

Logger writes structured session log entries to a file.

func New

func New() (*Logger, error)

New creates a new session logger. Log file is created at ~/.pi-go/log/yyyy-mm-dd/session-HH-MM-SS.log

func (*Logger) Close

func (l *Logger) Close() error

Close closes the log file.

func (*Logger) Error

func (l *Logger) Error(msg string)

Error logs an error.

func (*Logger) Errorf added in v0.0.15

func (l *Logger) Errorf(format string, v ...any)

Errorf logs an error with formatting.

func (*Logger) Info

func (l *Logger) Info(msg string)

Info logs an informational message.

func (*Logger) LLMText

func (l *Logger) LLMText(agent, text string)

LLMText logs streamed LLM text.

func (*Logger) Log

func (l *Logger) Log(e Entry)

Log writes a structured entry.

func (*Logger) Path

func (l *Logger) Path() string

Path returns the log file path.

func (*Logger) SessionStart

func (l *Logger) SessionStart(sessionID, model, mode string)

SessionStart logs session metadata at the beginning.

func (*Logger) Thinking added in v0.0.48

func (l *Logger) Thinking(agent, text string)

Thinking logs streamed model reasoning.

Reasoning is logged under its own type rather than folded into llm_text so a reader can still tell what the model said from what it only thought, and so tooling that reconstructs a transcript can drop it. It is logged at all because a turn that reasons and then produces nothing — a degenerate repetition loop, a refusal formed and discarded — otherwise leaves the session log with an unexplained gap between two tool results.

func (*Logger) ToolCall

func (l *Logger) ToolCall(agent, tool string, args any)

ToolCall logs a tool invocation.

func (*Logger) ToolResult

func (l *Logger) ToolResult(agent, tool, content string)

ToolResult logs a tool response.

func (*Logger) UserMessage

func (l *Logger) UserMessage(prompt string)

UserMessage logs a user prompt.

Jump to

Keyboard shortcuts

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