Documentation
¶
Index ¶
- Constants
- Variables
- func AppendHTTPStream(sessionId string, seqId int, chunk string) string
- func AppendToSessionLogFile(sessionId string, filename string, content string) string
- func AppendToStreamSessionLog(sessionId string, requestSeqId int, chunk string) string
- func AppendToStreamSessionLogJson(sessionId string, requestSeqId int, jsonableChunk any) string
- func Debug(msg string, args ...any)
- func DebugPersist(msg string, args ...any)
- func Error(msg string, args ...any)
- func ErrorPersist(msg string, args ...any)
- func FlushRemoteSink(ctx context.Context) error
- func GetSessionPrefix(sessionId string) string
- func Info(msg string, args ...any)
- func InfoPersist(msg string, args ...any)
- func NewTeeHandler(primary slog.Handler) slog.Handler
- func NewWriter() *writer
- func RecoverPanic(name string, cleanup func())
- func RemoteSinkActive() bool
- func SetRemoteSink(sink RemoteSink)
- func Subscribe(ctx context.Context) <-chan pubsub.Event[LogMessage]
- func Warn(msg string, args ...any)
- func WarnPersist(msg string, args ...any)
- func WriteChatResponseJson(sessionId string, requestSeqId int, response any) string
- func WriteHTTPRequest(sessionId string, seqId int, data any) string
- func WriteHTTPResponse(sessionId string, seqId int, data any) string
- func WriteRequestMessage(sessionId string, requestSeqId int, message string) string
- func WriteRequestMessageJson(sessionId string, requestSeqId int, message any) string
- func WriteToolResultsJson(sessionId string, requestSeqId int, toolResults any) string
- type Attr
- type LogData
- type LogMessage
- type RemoteSink
- type RemoteSinkFlusher
Constants ¶
const (
PersistTimeArg = "$_persist_time"
)
Variables ¶
var MessageDir string
Message Logging for Debug
Functions ¶
func AppendHTTPStream ¶ added in v0.200.0
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 DebugPersist ¶
func ErrorPersist ¶
func FlushRemoteSink ¶ added in v0.705.0
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 InfoPersist ¶
func NewTeeHandler ¶ added in v0.705.0
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 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 WarnPersist ¶
func WriteChatResponseJson ¶
func WriteHTTPRequest ¶ added in v0.200.0
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
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 WriteRequestMessageJson ¶
Types ¶
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
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.