logging

package
v0.705.0 Latest Latest
Warning

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

Go to latest
Published: Sep 11, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PersistTimeArg = "$_persist_time"
)

Variables

View Source
var MessageDir string

Message Logging for Debug

Functions

func AppendHTTPStream added in v0.200.0

func AppendHTTPStream(sessionId string, seqId int, chunk string) string

AppendHTTPStream appends a raw SSE stream chunk to {seqId}_http_stream.log in the session log directory. Used by the debug transport for streaming (text/event-stream) responses.

func AppendToSessionLogFile

func AppendToSessionLogFile(sessionId string, filename string, content string) string

func AppendToStreamSessionLog

func AppendToStreamSessionLog(sessionId string, requestSeqId int, chunk string) string

func AppendToStreamSessionLogJson

func AppendToStreamSessionLogJson(sessionId string, requestSeqId int, jsonableChunk any) string

func Debug

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

func DebugPersist

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

func Error

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

func ErrorPersist

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

func FlushRemoteSink added in v0.705.0

func FlushRemoteSink(ctx context.Context) error

FlushRemoteSink synchronously flushes the active remote sink, bounded by ctx, when one is set and it implements RemoteSinkFlusher. It is a no-op (returns nil) when there is no active sink or the sink does not support a synchronous flush. Used by RecoverPanic to push a panic record out before the process potentially exits.

func GetSessionPrefix

func GetSessionPrefix(sessionId string) string

func Info

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

func InfoPersist

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

func NewTeeHandler added in v0.705.0

func NewTeeHandler(primary slog.Handler) slog.Handler

NewTeeHandler wraps primary so every record also reaches the process-wide remote sink (internal/logging.SetRemoteSink) when one is active. Wrap it around the handler passed to slog.New in every place a *slog.Logger is constructed as Pando's default logger, so remote shipping survives a config.Reload() (which repeats that construction and calls slog.SetDefault again) without any special-casing.

func NewWriter

func NewWriter() *writer

func RecoverPanic

func RecoverPanic(name string, cleanup func())

RecoverPanic is a common function to handle panics gracefully. It logs the error, creates a panic log file with stack trace, and executes an optional cleanup function before returning.

func RemoteSinkActive added in v0.705.0

func RemoteSinkActive() bool

RemoteSinkActive reports whether a remote sink is currently installed.

func SetRemoteSink added in v0.705.0

func SetRemoteSink(sink RemoteSink)

SetRemoteSink installs (or, with a nil argument, clears) the process-wide remote sink. Called by internal/app's telemetry runtime when the user enables/disables remote logging, live, with no process restart required.

func Subscribe

func Subscribe(ctx context.Context) <-chan pubsub.Event[LogMessage]

func Warn

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

func WarnPersist

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

func WriteChatResponseJson

func WriteChatResponseJson(sessionId string, requestSeqId int, response any) string

func WriteHTTPRequest added in v0.200.0

func WriteHTTPRequest(sessionId string, seqId int, data any) string

WriteHTTPRequest writes raw HTTP request data (method, url, headers, body) to {seqId}_http_req.json in the session log directory. Used by the debug transport to record exactly what was sent to the provider API.

func WriteHTTPResponse added in v0.200.0

func WriteHTTPResponse(sessionId string, seqId int, data any) string

WriteHTTPResponse writes raw HTTP response data (status, headers, body) to {seqId}_http_resp.json in the session log directory. Used by the debug transport to record exactly what the provider API returned.

func WriteRequestMessage

func WriteRequestMessage(sessionId string, requestSeqId int, message string) string

func WriteRequestMessageJson

func WriteRequestMessageJson(sessionId string, requestSeqId int, message any) string

func WriteToolResultsJson

func WriteToolResultsJson(sessionId string, requestSeqId int, toolResults any) string

Types

type Attr

type Attr struct {
	Key   string
	Value string
}

type LogData

type LogData struct {
	*pubsub.Broker[LogMessage]
	// contains filtered or unexported fields
}

func (*LogData) Add

func (l *LogData) Add(msg LogMessage)

func (*LogData) List

func (l *LogData) List() []LogMessage

type LogMessage

type LogMessage struct {
	ID          string
	Time        time.Time
	Level       string
	Persist     bool          // used when we want to show the mesage in the status bar
	PersistTime time.Duration // used when we want to show the mesage in the status bar
	Message     string        `json:"msg"`
	Attributes  []Attr
}

LogMessage is the event payload for a log message

func List

func List() []LogMessage

type RemoteSink added in v0.705.0

type RemoteSink interface {
	// Enabled reports whether the sink currently wants records at level —
	// e.g. *internal/telemetry.Shipper checks level against its configured
	// minimum level and whether it has been disabled (by an ingest
	// rejection or a recovered worker panic). The tee handler consults this
	// both from its own Enabled (so slog's log functions can skip building
	// args entirely when neither the primary handler nor the sink wants the
	// record) and from Handle (so a record the sink does not want is never
	// forwarded at all, not even to be dropped inside the sink itself).
	Enabled(level slog.Level) bool
	// Handle is called once per shipped record, already past whatever level
	// filtering the tee handler applies. The sink is responsible for its own
	// additional filtering (e.g. a configured minimum level), batching, and
	// never blocking the caller.
	Handle(ctx context.Context, t time.Time, level slog.Level, msg string, attrs []slog.Attr)
}

RemoteSink receives every log record the tee handler (see tee_handler.go) decides to ship, in addition to the primary (local) handler. It is implemented by *internal/telemetry.Shipper; this interface is kept small and local to internal/logging so this package never has to import internal/telemetry (see the dependency rule in the remote telemetry plan: internal/logging must stay free of internal/config and internal/telemetry wiring, which instead lives in internal/app).

type RemoteSinkFlusher added in v0.705.0

type RemoteSinkFlusher interface {
	Flush(ctx context.Context) error
}

RemoteSinkFlusher is an optional extension a RemoteSink can implement to support a short, synchronous flush — used on the panic-recovery path, where the process may be about to exit and the sink's normal interval/threshold batching would otherwise never run.

Jump to

Keyboard shortcuts

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