logger

package
v0.3.9 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2026 License: MIT Imports: 11 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.

func SafeBaseURL added in v0.0.80

func SafeBaseURL(raw string) string

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

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, provider, backend, baseURL, 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.

type StdLog added in v0.2.9

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

StdLog diverts the standard library's default logger away from the terminal.

Dependencies such as adk call log.Printf, which writes to stderr. On the TUI's alternate screen that output is painted into the frame and stays there until the next full repaint. The session log does not exist yet when the TUI starts, so lines are held until Attach hands them a destination.

func RedirectStdLog added in v0.2.9

func RedirectStdLog() *StdLog

RedirectStdLog points log's default output at the returned StdLog. It must run before anything that can log, which means before the TUI takes the screen. Call Restore to put the previous output back.

func (*StdLog) Attach added in v0.2.9

func (s *StdLog) Attach(l *Logger)

Attach sends held and later lines to l. A nil l is ignored.

func (*StdLog) Detach added in v0.2.9

func (s *StdLog) Detach()

Detach stops forwarding, so a late line cannot reach a closed Logger. Lines after Detach are discarded rather than returned to the terminal.

func (*StdLog) Restore added in v0.2.9

func (s *StdLog) Restore()

Restore reinstates the logger output and flags that were in place before RedirectStdLog.

func (*StdLog) Write added in v0.2.9

func (s *StdLog) Write(p []byte) (int, error)

Write implements io.Writer for the standard logger.

Jump to

Keyboard shortcuts

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