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 ¶
- func HTTPSink(l *Logger) func(httplog.Entry)
- func SafeBaseURL(raw string) string
- type Entry
- type Logger
- func (l *Logger) Close() error
- func (l *Logger) Error(msg string)
- func (l *Logger) Errorf(format string, v ...any)
- func (l *Logger) Info(msg string)
- func (l *Logger) LLMText(agent, text string)
- func (l *Logger) Log(e Entry)
- func (l *Logger) Path() string
- func (l *Logger) SessionStart(sessionID, model, provider, backend, baseURL, mode string)
- func (l *Logger) Thinking(agent, text string)
- func (l *Logger) ToolCall(agent, tool string, args any)
- func (l *Logger) ToolResult(agent, tool, content string)
- func (l *Logger) UserMessage(prompt string)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func HTTPSink ¶ added in v0.0.51
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.
func SafeBaseURL ¶ added in v0.0.80
SafeBaseURL removes credentials and query/fragment data before an endpoint is persisted in a session log.
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)
Provider string `json:"provider,omitempty"` // provider name (logged once at start)
Backend string `json:"backend,omitempty"` // selected backend (logged once at start)
BaseURL string `json:"base_url,omitempty"` // selected endpoint, without credentials
// 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 ¶
New creates a new session logger. Log file is created at ~/.pi-go/log/yyyy-mm-dd/session-HH-MM-SS.log
func (*Logger) SessionStart ¶
SessionStart logs session metadata at the beginning.
func (*Logger) Thinking ¶ added in v0.0.48
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) ToolResult ¶
ToolResult logs a tool response.
func (*Logger) UserMessage ¶
UserMessage logs a user prompt.